我有一个使用ui.router包构建的Angular应用程序用于URL路由.我想更改它,以便如果用户尝试导航到他们已经在的页面,路由器将重新加载该状态而不是什么都不做.根据http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$ state#go,$ state.go 确实采用了一个重新加载参数,但是这样做的确如此它默认为false.现在,在我的代码中重写每个调用$ state.go和每个ui-sref以将reload设置为true的想法都是一个糟糕的想法.我想要的是改变$ state.go的那个参数的默认值的一些方法,或者至少是ui-sref装饰器.
在http://angular-tips.com/blog/2013/09/experiment-decorating-directives/之后,我尝试至少扩展ui-sref指令(因为除了明确的指令之外还有更多的指令) $ state.go电话)
myApp.config(function($provide) {
// override ui-sref to have the reload option default to true.
$provide.decorator('uiSrefDirective', function($delegate){
var directive = $delegate[0];
var link = directive.link;
directive.compile = function() {
return function(scope, element, attrs) {
if(attrs.uiSrefOpts == null){
attrs.uiSrefOpts = {};
}
if(attrs.uiSrefOpts.reload == null){
attrs.uiSrefOpts.reload = true;
}
console.log(arguments);
link.apply(this, arguments);
};
};
return $delegate;
});
Run Code Online (Sandbox Code Playgroud)
然而,这实际上似乎没有任何成就,即使它确实如此,它实际上也不会影响$ state.go.有没有人有任何想法如何在ui.router代码中手动更改这种行为?