Error: Argument is not a function, got undefined

前端 未结 17 1835
不思量自难忘°
不思量自难忘° 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:14

    FIRST. check if you have correct controller in the route definitions, same as the controller names that you are defining

    communityMod.config(['$routeProvider',
      function($routeProvider) {
        $routeProvider.
          when('/members', {
            templateUrl: 'modules/community/views/members.html',
            controller: 'CommunityMembersCtrl'
          }).
          otherwise({
            redirectTo: '/members'
          });
      }]);
    
    communityMod.controller('CommunityMembersCtrl', ['$scope',
        function ($scope) {
            $scope.name = 'Hello community';
        }]);
    

    different controller names in this example will lead to errors, but this example is correct

    SECOND check if you have imported your javascript file:

提交回复
热议问题