作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
HTML:
<div ng-repeat="obj in arr">
<custom-directive status-stored-in="obj"></custom-directive>
</div>
问题:
我为大量的 obj
内置了翻页功能。这意味着 arr
的值,代表 obj
的当前页面,将会改变。但是,status-stored-in="obj"
部分中的 obj
不会随着更改而刷新。
现在我的解决方案是在 customDirective
中添加一个 ng-if
,来回闪烁它的值以强制重新编译。有没有其他等效的、更简洁的方法来处理这个问题?
自定义指令的开始:
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);
});
}
关于javascript - Angular : How to force recompile directive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28579849/
我是一名优秀的程序员,十分优秀!