【发布时间】:2016-02-26 20:33:28
【问题描述】:
Angular 1.5 引入了components(特殊类型的指令)
对于指令我们可以这样写:
app.directive('myDirective',
['$timeout','$mdToast','$rootScope', // <-- injection
function ($timeout, $mdToast,$rootScope) {
return {
link: {},
//...
}
}
我们如何为组件编写注入?
我肯定会写,比如:
app.component('myComponent', {
restrict: 'E',
bindings: {
data: '='
},
templateUrl: 'template.html',
controllerAs: 'vm',
controller: 'myComponentCtrl'
});
和:
app.controller('myComponentCtrl',
['$scope', '$timeout',
function ($scope, $timeout) {
// ....
}]);
但我想写内置控制器,比如:
app.component('myComponentCtrl', {
templateUrl: 'template.html',
controller: function($scope, $timeout) {
//...
}
});
上面提到的样式缩小(GRUNT)会破坏我的代码Unknown provider: aProvider <- a,
那么如何为组件编写正确的注入?
有什么想法吗?
我使用的演示Plunker
【问题讨论】:
标签: angularjs