控制器不是Angular函数

时间:2016-11-29 07:06:15

标签: angularjs

尽管已经注册,但我无法让控制器工作

我正在定义我的控制器,如下所示

(function () {
  'use strict';

  function EntityModulesCtrl(UserManagement, getEntityModules) {
    let ctrl = this;

    console.log('loggging from entityModules ctrl...');
    console.log(getEntityModules);

    ctrl.saveMapping = function () {
      let params = {
        modules: ctrl.selectedModules,
        entity: ctrl.selectedEntity
      };

      UserManagement.saveModuleEntityMapping(params).then(function(res){
        console.log(res);
      });
    }
  }

  angular.module('mean.user_management')
    .controller('EntityModulesCtrl', EntityModulesCtrl);

  EntityModulesCtrl.$inject = ['UserManagement', 'getEntityModules'];
});

我的路线是

(function() {
  'use strict';

  function UserManagement($stateProvider) {
    $stateProvider.state('dashboard', {
      url: '/dashboard',
      templateUrl: 'user_management/views/index.html',
      resolve: {
        // dashboardConfig: function () {
        //   var roleType =  localStorage.getItem('roleType');
        // }
      }
    }).state('userManagement circles example', {
      url: '/userManagement/example/:circle',
      templateUrl: 'user_management/views/example.html'
    }).state('dashboard.entityModulesMapping', {
      url: '/userManagement/mapEntityModules',
      templateUrl: 'user_management/views/entityModules.html',
      controller: 'user_management/controllers/EntityModulesCtrl.js',
      controllerAs: '$ctrl',
      resolve: {
        getEntityModules: function (UserManagement) {
          return UserManagement.getEntityModules().then(function (res) {
            console.log("logging from mapEntityModules resolve...");
            console.log(res);
            return res;
          })
        }
      }
    });
  }

  angular.module('mean.user_management')
    .config(UserManagement);

  UserManagement.$inject = ['$stateProvider'];

})();

我尝试过使用

controller: EntityModulesCtrl
controller: 'EntityModulesCtrl'
controller: "path_to_my_controller_file"

但它不起作用。

2 个答案:

答案 0 :(得分:0)

您的模块应该具有依赖性,

angular
    .module('mean.user_management',[])
    .config(UserManagement);

答案 1 :(得分:0)

在您的脚本中添加

(12,)
代替  controller: 'EntityModulesCtrl',

并确保将controllerscript文件添加到html页面。

controller: 'user_management/controllers/EntityModulesCtrl.js',