[英]Angular: How to force recompile directive?
HTML:
<div ng-repeat="obj in arr">
<custom-directive status-stored-in="obj"></custom-directive>
</div>
問題:
我為大量的obj
內置了翻頁。 這意味着代表obj
的當前頁面的arr
的值將改變。 然而, obj
的status-stored-in="obj"
部分不與改變刷新。
現在我的解決方案是在customDirective
添加一個ng-if
, customDirective
閃爍它的值以強制重新編譯。 有沒有其他等效,更簡潔的方式來處理這個?
自定義指令的開頭:
module.directive 'checkbox', (checkboxHooks) ->
restrict: 'E'
scope:
hook: '='
hookedTo: '='
statusStoredIn: '='
templateUrl: 'templates/checkbox.html'
link: (scope, element, attr) ->
在您的指令鏈接功能中,您需要觀察status-stored-in
更改,然后重新編譯它,例如:
link: function(scope, element) {
scope.$watch('statusStoredIn', function() {
element.html(statusStoredIn);
$compile(element.contents())(scope);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.