Using AngularJS with Scala Play, I\'m getting this error.
Error: Argument \'MainCtrl\' is not a function, got undefined
I\'m try
I had the same error with a big mistake:
appFormid.controller('TreeEditStepControlsCtrl', [$scope, function($scope){
}]);
You see ? i forgot the '' around the first $scope, the right syntax is of course:
appFormid.controller('TreeEditStepControlsCtrl', ['$scope', function($scope){
}]);
A first error i didn't see immediatly was: "$scope is not defined", followed by "Error: [ng:areq] Argument 'TreeEditStepControlsCtrl' is not a function, got undefined"
In my case it was a simple typo in index.html
:
<script src="assets/javascript/controllers/questionssIndexController.js"></script>
that should have been
<script src="assets/javascript/controllers/questionsIndexController.js"></script>
without the extra s
in the controller's name.
I got sane error with LoginController, which I used in main index.html. I found two ways to resolve:
setting $controllerProvider.allowGlobals(), I found that comment in Angular change-list "this option might be handy for migrating old apps, but please don't use it in new ones!" original comment on Angular
app.config(['$controllerProvider', function($controllerProvider) { $controllerProvider.allowGlobals(); }]);
wrong contructor of registering controller
before
LoginController.$inject = ['$rootScope', '$scope', '$location'];
now
app.controller('LoginController', ['$rootScope', '$scope', '$location', LoginController]);
'app' come from app.js
var MyApp = {};
var app = angular.module('MyApp ', ['app.services']);
var services = angular.module('app.services', ['ngResource', 'ngCookies', 'ngAnimate', 'ngRoute']);
This seriously took me 4 HOURS (including endless searches on SO) but finally I found it: by mistake (unintentionally) I added a space somewhere.
Can you spot it?
angular.module('bwshopper.signup').controller('SignupCtrl ', SignupCtrl);
So ... 4 hours later I saw that it should be:
angular.module('bwshopper.signup').controller('SignupCtrl', SignupCtrl);
Almost impossible to see with just the naked eye.
This stresses the vital importance of revision control (git or whatever) and unit/regression testing.
To fix this problem, I had to discover that I misspelled the name of the controller in the declaration of Angular routes:
.when('/todo',{
templateUrl: 'partials/todo.html',
controller: 'TodoCtrl'
})
If you are in a submodule, don't forget to declare the module in main app. ie :
<scrip>
angular.module('mainApp', ['subModule1', 'subModule2']);
angular.module('subModule1')
.controller('MyController', ['$scope', function($scope) {
$scope.moduleName = 'subModule1';
}]);
</script>
...
<div ng-app="mainApp">
<div ng-controller="MyController">
<span ng-bind="moduleName"></span>
</div>
If you don't declare subModule1 in mainApp, you will got a "[ng:areq] Argument "MyController" is not a function, got undefined.