而不是在控制器中指定所有服务,例如:
mainApp.controller('MultiController', ['$scope', '$attrs', '$branchesService', '$repositoriesService', function ($scope, $attrs, $branchesService, $repositoriesService) {
console.log('multiController instantiated');
var vm = this;
// private idu funkcija definition bez scope
vm.init = function(mod) {
vm.mod = mod;
if (mod == "branch") {
console.log('MultiController branchesService');
vm.service = $branchesService;
} else {
console.log('MultiController repoService');
vm.service = $repositoriesService;
}
vm.items = [];
vm.selectedItem = null;
vm.error = 'no Error at the moment...';
loadRemoteData();
console.log('multiController.init()');
}
vm.init($attrs.mod);
是否可以使用 $inject ?我正在使用 $attrs 从 html 获取规范,我应该使用哪个服务。