Hello,

Part of my index.html looks like this
         <div class="container" ng-include="'views/posts.html'" 
ng-controller="PostsCtrl" />

        <script src="scripts/app.js"></script>
        <script src="scripts/controllers/posts.js"></script>
        <script src="scripts/services/post.js"></script>

I refer to my angular app in app.js like this: 

var app = angular.module('angularJsApp',[
        'ngRoute'
    ]
);

then in scripts/controllers/posts.js I cannot define a controller like this

app.controller("PostsCtrl",['$scope', function($scope) {
    $scope.posts = [];
    $scope.post = {title:'',url:'http://'};
    $scope.addPost = function(){
        $scope.posts.push($scope.post);
        $scope.post = {title:'',url:'http://'};
    };
    $scope.deletePost = function(key){
        $scope.posts.splice(key,1);
    };
    $scope.resetPost = function(){
        $scope.post = {title:'',url:'http://'};
    };
}]);

I get an error 

"Error: [ng:areq] Argument 'PostsCtrl' is not a function, got undefined"

If I do this

console.log(app) 
app.controller("PostsCtrl",['$scope', function($scope) {

I get Object { _invokeQueue=[1], _runBlocks=[0], requires=[1], more...}
in the FireBug console tab. This looks suspiciously like the angular object 
with controller function and all...

I _have_ to refer to the app this way:
angular.module('angularJsApp').
controller("PostsCtrl",['$scope', function($scope) {
[...]

then everything works fine.

Why can't angular be called on a global object?

Marc
Wh

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to