简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM