Angular.js filters and functions on scope that is changing every second

故事扮演 提交于 2019-12-02 21:33:31

问题


The problem. I have a table of entries($scope.entries), each row(ng-repeat) with 5 columns, 2 of those columns have custom made filter for various transformations.

Now in the same scope I have active_entry($scope.active_entry), which is changing every seconds, because of it and how angular works(I guess), the whole scope is being constantly checked and my filters executed.

This causes Watch Expressions in Batarang to go sky high over the time.

How can I use create some sort of isolated scope for the active_entry so my filters are not rended over and over again every second?

Is making a directive the only way to create an isolated scope? Would it work? What if I needed values from the isolated scope later on in the controller?


回答1:


You are asking quite a few questions in your question. It would be better to ask them each in separate SO questions.

Anytime an Angular digest cycle runs, all watches and filters will run. Changing things "inside" of Angualar will cause a digest cycle to run. How are you changing $scope.active_entry? If you can change it outside of Angular, you might be able to do what you want. As you mentioned, you'll also have to put that property into a new child scope (scope: true) or isolate scope (scope: {...}), then you could call $scope.digest() (after you change active_entry) to only digest that scope.

Creating a directive would be the best way to create an isolate scope. You can create a child scope with ng-controller or a directive.

See also https://groups.google.com/d/topic/angular/1XtEAX93ces/discussion



来源:https://stackoverflow.com/questions/15929191/angular-js-filters-and-functions-on-scope-that-is-changing-every-second

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!