我试图从angular1.5组件初始化test.service.js
而我真的不知道如何做到这一点。我已将此结构用于角度分量:
var testComponent = {
templateUrl: "app/components/test.component.html",
controllerAs: "mvm",
bindings:{
bindingInput: "=",
},
controller: function(){
var mvm = this;
}
};
angular.module('myApp').component('testComponent', testComponent);
答案 0 :(得分:1)
您可以将服务权限注入控制器,如下所示:
....
controller: function(testService) {
var mvm = this;
}
};
为防止{min}插件对testService
进行模糊处理,请让注入服务器了解相关性。
var Controller = function(testService) {
// Your controller code here
};
Controller.$inject = ['testService'];
var testComponent = {
...
controller: Controller, // Assign controller in component
...
};
答案 1 :(得分:1)
使用控制器注入它,如下所示:
...
},
controller: ['testService', function(testService){
var mvm = this;
}],
...