Reputation: 3791
I'm new to Angular and I'm just following a tutorial. I've got this error and can't understand why.
Argument 'CommentsCtrl' is not a function, got undefined
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>tuto</title>
</head>
<body ng-app>
<div ng-controller="CommentsCtrl">
<div ng-repeat="comment in comments">
{{comment.name}}
{{comment.comment}}
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>
function CommentsCtrl($scope) {
$scope.comments = [
{
"name": "Terra",
"comment": "Eu reprehenderit id excepteur do commodo ad do. Amet occaecat in ex "
},
// other comments ...
]
}
</script>
</body>
</html>
Upvotes: 1
Views: 116
Reputation: 20445
from Angular 1.3.x you cant define global controllers by defualt
use .controller()
angular.module('myModule')
.controller('CommentsCtrl'.function CommentsCtrl($scope) {
$scope.comments = [
{
"name": "Terra",
"comment": "Eu reprehenderit "
},
// other comments ...
]
})
or set global controller option
angular.module('myModule').config(['$controllerProvider', function($controllerProvider) {
$controllerProvider.allowGlobals();
}]);
in html
<body ng-app="myModule">
Upvotes: 1