2

I am trying to improve performance on an angularJS app. my colleague told me that this....

<div ng-bind="getValue()"></div> //where this returns 'value'

Is less performant than this...

<div ng-bind="value"></div>

Is this true? If so why?

Exitos
  • 29,230
  • 38
  • 123
  • 178

2 Answers2

0

If your function simply return a value, and doesn't accept any parameters, then it's not a good practice to to so: let's say you want to change that value later on, as a result of some function or user action.

Alberto
  • 399
  • 1
  • 6
  • 19
0

this only makes sense if it is one way binding. as it is a function and you don't need to watch/observe the changes might have some benefits but then there is a binding called one-way binding in ng. It would be wiser if you use it.

Edit: it is called one-time binding and only available AngularJS 1.3. But there is a good SO Question for it and alternative approach for 1.2, also have a very simple comparison .

Community
  • 1
  • 1
Onur Topal
  • 3,042
  • 1
  • 24
  • 41