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?
Basically the double-curly syntax is more naturally readable and requires less typing.
Both cases produce the same output but.. if you choose to go with
{{}}
there is a chance that the user will see for some milliseconds the{{}}
before your template is rendered by angular. So if you notice any{{}}
then is better to useng-bind
.Also very important is that only in your index.html of your angular app you can have un-rendered
{{}}
. If you are using directives so then templates, there is no chance to see that because angular first render the template and after append it to the DOM.{{...}}
is meant two-way data binding. But, ng-bind is actually meant for one-way data binding.Using ng-bind will reduce the number of watchers in your page. Hence ng-bind will be faster than
{{...}}
. So, if you only want to display a value and its updates, and do not want to reflect its change from UI back to the controller, then go for ng-bind. This will increase the page performance and reduce the page load time.This is because with
{{}}
the angular compiler considers both the text node and it's parent as there is a possibility of merging of 2{{}}
nodes. Hence there are additional linkers that add to the load time. Of course for a few such occurrences the difference is immaterial, however when you are using this inside a repeater of large number of items, it will cause an impact in slower runtime environment.The reason why Ng-Bind is better because,
When Your page is not Loaded or when your internet is slow or when your website loaded half, then you can see these type of issues (Check the Screen Shot with Read mark) will be triggered on Screen which is Completly wired. To avoid such we should Ng-bind
You can refer to this site it will give you a explanation which one is better as i know {{}} this is slower than ng-bind.
http://corpus.hubwiz.com/2/angularjs/16125872.html refer this site.
ng-bind has its problems too.When you try to use angular filters, limit or something else, you maybe can have problem if you use ng-bind. But in other case, ng-bind is better in UX side.when user opens a page, he/she will see (10ms-100ms) that print symbols ( {{ ... }} ), that's why ng-bind is better.