HTML:
<div ng-repeat="obj in arr">
<custom-directive status-stored-in="obj"></custom-directive>
</div>
Problem:
我内置了翻页功能,可以处理大量的内容obj
s。这意味着arr
, 代表当前页面obj
s,将会改变。但是,那obj
in the status-stored-in="obj"
部分不会随着更改而刷新。
现在我的解决方案是添加一个ng-if
in customDirective
,来回闪烁其值以强制重新编译。有没有其他等效、更简洁的方法来处理这个问题?
Edit:
自定义指令的开头:
module.directive 'checkbox', (checkboxHooks) ->
restrict: 'E'
scope:
hook: '='
hookedTo: '='
statusStoredIn: '='
templateUrl: 'templates/checkbox.html'
link: (scope, element, attr) ->
要点是它需要获取一个对象,用于存储checked
地位。全部内容可以在这里找到:[coffee https://github.com/Luxiyalu/angular-checkbox-set/blob/master/angular-checkbox-set.coffee/js https://github.com/Luxiyalu/angular-checkbox-set/blob/master/angular-checkbox-set.js].
在你的指令链接函数中你需要观察status-stored-in
进行更改,然后重新编译它,例如:
link: function(scope, element) {
scope.$watch('statusStoredIn', function() {
element.html(statusStoredIn);
$compile(element.contents())(scope);
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)