Error: Argument is not a function, got undefined

前端 未结 17 1895
不思量自难忘°
不思量自难忘° 2020-12-07 19:35

Using AngularJS with Scala Play, I\'m getting this error.

Error: Argument \'MainCtrl\' is not a function, got undefined

I\'m try

17条回答
  •  长情又很酷
    2020-12-07 20:06

    I got sane error with LoginController, which I used in main index.html. I found two ways to resolve:

    1. 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(); }]);

    2. 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']);
    

提交回复
热议问题