0

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?

fxck
  • 4,898
  • 8
  • 56
  • 94

1 Answers1

0

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

Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
  • It's sort of a timer, so active_entry is being updated every second with $timeout.. – fxck Apr 11 '13 at 06:16
  • I don't get it, I created an isolated scope http://plnkr.co/edit/8UqVXWFTdutIQ4sHDPAe?p=preview and filters on parent scope are still being executed every second(check console).. – fxck Apr 14 '13 at 09:05
  • Ah I see, the third parameter at $timeout and the $digest(). – fxck Apr 14 '13 at 09:21