本文介绍了在angularjs中如何装饰$stateProvider Provider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这种类型的装饰器适用于服务和工厂.我希望它也能与供应商合作.我尝试了以下方法来装饰 ui-router 的 $stateProvider
:
This type of decorator works with services and factories. I expected it to work with providers as well. I've tried the following to decorate ui-router's $stateProvider
:
app.config(function($provide) {
$provide.decorator('$state', function ($delegate) {
return $delegate;
});
});
推荐答案
应该也一样吧?见 plunk @ http://plnkr.co/edit/rSFo1xCoRHjWmrSjJBN1
It should work just the same? See plunk @ http://plnkr.co/edit/rSFo1xCoRHjWmrSjJBN1
var app = angular.module('plunker', []);
app.provider('provider', function () {
this.$get = function () {
var provider = {};
var value = 'test';
provider.get = function() {
return value;
}
provider.set = function(param) {
value = param;
}
return provider;
}
});
app.config(function($provide) {
$provide.decorator('provider', function ($delegate) {
$delegate.set('delegate');
return $delegate;
});
});
app.controller('MainCtrl', function($scope, provider) {
$scope.name = provider.get();
});
这篇关于在angularjs中如何装饰$stateProvider Provider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!