问题描述
我有角指令的一个问题。当我通过修改 templateUrl
引用的文件的内容,结果没有出现,直到我删除缓存。我有以下的code:
I have a problem with angular directives. When I edit the content of a file referenced via templateUrl
, the result doesn't appear until I delete the cache. I have the following code:
Directive.js
Directive.js
.directive('appMainsec',['$window', function ($window){
var objectMainSec = {
restrict: 'A',
templateUrl: 'partials/app-mainsec.html',
controller: function (){},
controllerAs: 'MainSectCtrl',
link: function ($scope,elemnt,attr){
elemnt.css('height', ($window.innerHeight - ($window.innerHeight * .25)) + 'px');
}
};
return objectMainSec;
}]);
APP-mainsec.html
app-mainsec.html
<div><h1>Principal</h1></div>
和index.html
and index.html
...
<div app-mainsec></div>
...
在更改&LT; H1&GT;喜&LT; / H1&GT;
到&LT; H1&GT;你好&LT; / H1&GT;
,指令的视图不会更新,直到我删除缓存。
When I change <h1>Hi</h1>
to <h1>Hello</h1>
, the view of directive doesn't update until I delete the cache.
推荐答案
这其中的原因是,在角开始时得到一个文件只有一次。您可以尝试使用templateUrl的功能和附加的时间戳,所以你每次都得到新的模板URL。
The reason for that is that Angular fetch a file only once at the begining. You can try to use templateUrl as function and append timestamp so you get new template url each time.
templateUrl: function() {
return 'partials/app-mainsec.html?' + +new Date();
}
但也许,这将会让你的指令,只有当指令将被编译。
But probably, it will refresh your directive only when directive will be compiled.
这篇关于AngularJS指令templateUrl不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!