javascriptangularjsng-bind

AngularJS : Why ng-bind is better than {{}} in angular?


I was in one of the angular presentation and one of the person in the meeting mentioned ng-bind is better than {{}} binding.

One of the reason, ng-bind put the variable in the watch list and only when there is a model change the data get pushed to view, on the other hand, {{}} will interpolate the expression every time (I guess it is the angular cycle) and push the value, even if the value changed or not.

Also it is said that, if you have not much data in on the screen you can use {{}} and the performance issue will not be visible. Can someone shed some light on this issue for me?


Solution

  • If you are not using ng-bind, instead something like this:

    <div>
      Hello, {{user.name}}
    </div>
    

    you might see the actual Hello, {{user.name}} for a second before user.name is resolved (before the data is loaded)

    You could do something like this

    <div>
      Hello, <span ng-bind="user.name"></span>
    </div>
    

    if that's an issue for you.

    Another solution is to use ng-cloak.