angularjs ui-router 刷新不缓存

angularjs ui-router 刷新不缓存

加了cache:false不行,在页面ui-sref 后面加ui-sref-opts=”{reload:true}” 不行
网上的解决方法:$injector.get(‘$templateCache’).removeAll(); or $templateCache.removeAll();
都是一次移除所有缓存 不实际

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//手动移除缓存
$rootScope.$on('$stateChangeSuccess',function(event, toState, toParams, fromState, fromParams){

//移除模版缓存
var removeCache = function(v){
if(typeof(v) == 'String')
$templateCache.remove(v);
else if(typeof(v) =='function')
$templateCache.remove(v(toParams));
}
if(toState.cache === false){
if(typeof(toState.templateUrl) != 'undefined')
removeCache(toState.templateUrl);
else if(typeof(toState.views) != 'undefined')
for(var v in toState.views)
removeCache(toState.views[v].templateUrl);
}//cache

});

//配置文件信息
.state('app.settings.siteManage.details',{//站点管理 未翻译
url:'/details/:id/:type',
cache:false,
views: {
"header@app" : {
templateUrl : $ctx +"/main/settings/header"
},
"container@app" : {
templateUrl: function($routeParams){return '/siteManage/details/'+$routeParams.id+'/'+$routeParams.type;},
controller:'SiteManageIndexController'
}
},
resolve:{
deps:[
'$ocLazyLoad',
function($ocLazyLoad){
return $ocLazyLoad.load(['/static/js/controllers/SiteManage.js' ]);
}
]
}
})