5

http://plnkr.co/edit/b1yGAwkzojF4BFWgpMsv?p=preview

Why did filter trigger some many times?

I guess {{name|test}} will tigger twice because the name is null at first, then got value at controller.

Why did it trigger filter when include template?

Ryan B
  • 3,364
  • 21
  • 35
atian25
  • 4,166
  • 8
  • 37
  • 60

1 Answers1

9

Every filter is called at least once every digest cycle. This SO answer has a fiddle that demonstrates this.

When a template is loaded, you are in a digest cycle, so all filters will be called.

Community
  • 1
  • 1
Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
  • That's crazy... The angular told us it will only render when scope changed, but in this case, it's that mean we will got many unnecessary calc, what about the performance? what should we do to avoid this? – atian25 Aug 20 '13 at 01:14
  • 3
    @atian25, one way is to avoid the filter running is to not use a filter -- by that I mean calculate the filtered value once in the controller, store the result on a scope property, then use that property in the view. This obviously will not work for every filter, but it will for some. – Mark Rajcok Aug 20 '13 at 01:56