admin管理员组文章数量:1194346
I need to use sublist
directive in few places of the page, and it should contain sometimes full fields
list, but sometimes filtered. Here is my naive approach:
HTML:
<div ng-controller="MainCtrl">
<sublist fields="fields" /> <!-- This one is OK -->
<sublist fields="fields | filter: 'Rumba'" /> <!-- This one raises error -->
</div>
Javascript:
angular.module('myApp', [])
.directive('sublist', function () {
return {
restrict: 'E',
scope: { fields: '=' },
template: '<div ng-repeat="f in fields">{{f}}</div>'
};
})
.controller('MainCtrl', function($scope) {
$scope.fields = ['Samba', 'Rumba', 'Cha cha cha'];
});
/
When I try to use filter I'm getting this error:
Error: 10 $digest() iterations reached. Aborting!
Is there a solution for this problem?
I need to use sublist
directive in few places of the page, and it should contain sometimes full fields
list, but sometimes filtered. Here is my naive approach:
HTML:
<div ng-controller="MainCtrl">
<sublist fields="fields" /> <!-- This one is OK -->
<sublist fields="fields | filter: 'Rumba'" /> <!-- This one raises error -->
</div>
Javascript:
angular.module('myApp', [])
.directive('sublist', function () {
return {
restrict: 'E',
scope: { fields: '=' },
template: '<div ng-repeat="f in fields">{{f}}</div>'
};
})
.controller('MainCtrl', function($scope) {
$scope.fields = ['Samba', 'Rumba', 'Cha cha cha'];
});
http://jsfiddle.net/GDfxd/14/
When I try to use filter I'm getting this error:
Error: 10 $digest() iterations reached. Aborting!
Is there a solution for this problem?
Share Improve this question edited Apr 5, 2020 at 14:10 Dan 63.1k18 gold badges109 silver badges118 bronze badges asked Jun 19, 2013 at 18:19 DfrDfr 4,17510 gold badges45 silver badges65 bronze badges2 Answers
Reset to default 24The $digest iterations error typically happens when there is a watcher that changes the model. In the error case, the isolate fields
binding is bound to the result of a filter. That binding creates a watcher. Since the filter returns a new object from a function invocation each time it runs, it causes the watcher to continually trigger, because the old value never matches the new (See this comment from Igor in Google Groups).
A good fix would be to bind fields
in both cases like:
<sublist fields="fields" /></sublist>
And add another optional attribute to the second case for filtering:
<sublist fields="fields" filter-by="'Rumba'" /></sublist>
Then adjust your directive like:
return {
restrict: 'E',
scope: {
fields: '=',
filterBy: '='
},
template: '<div ng-repeat="f in fields | filter:filterBy">'+
'<small>here i am:</small> {{f}}</div>'
};
Note: Remember to close your sublist
tags in your fiddle.
Here is a fiddle
Corrected Fiddle
Check a related post here.
In the fiddle you will need to have closing tags. While you can still have self contained tags like the one you have.
<sublist fields="fields" filter="'Rumba'"/> <!-- Tested in chrome -->
本文标签: javascriptAngularjs pass filter to directive bidirectional (3939) attributeStack Overflow
版权声明:本文标题:javascript - Angular.js pass filter to directive bi-directional ('=') attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738461931a2088079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论