我正在尝试将多个服务添加到模块控制器。但是我在控制器中调用的每个函数中都未定义(调用服务)
模块代码
angular.module('planexecution', ['products', 'tactics', 'scorecard'])
.config(['$stateProvider', planexecution.config])
.factory('debugService', [planexecution.debugService])
.factory('planexecutionQueries', [planexecution.queries])
.service('planexecutionService', ['$q', '$resource', 'planexecutionQueries', 'debugService', planexecution.planexecutionService])
.controller('planexecutionMainCtrl', ['wamCommon', 'debugService', 'planexecutionService','$state', planexecution.planexecutionMainCtrl()]);
在控制器上:
(function() {
Planexecution = function() {
var __this = this;
__this.planexecutionMainCtrl = function(wamCommon, debugService, planexecutionService, $state) {
var __this = this;
__this.allSSO = planexecutionService.getSSOjson();
};
};
})();
错误:
planexecutionCtrl.js:11 Uncaught TypeError: Cannot read property 'getSSOjson' of undefined
所以注入服务时出了什么问题?
在注入依赖项时使用内联数组批注:
__this.planexecutionMainCtrl = ['wamCommon', 'debugService', 'planexecutionService', '$state',
function(wamCommon, debugService, planexecutionService, $state) {
...
}];
隐式注释在代码最小化时不起作用,请在此处阅读更多内容:https://docs.angularjs.org/guide/di