Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in performance between interpolation {{}} and [innerText] - angular 2

In Angular 1 using ng-bind gave you a performance boost over interpolation.

Is this still the case in Angular 2? Should I use [innerText] over interpolation.

E.g.

<p>{{slower}}</p>
<p [innerText]="faster"></p>
like image 686
Graham Fowles Avatar asked Nov 24 '16 10:11

Graham Fowles


1 Answers

We often have a choice between interpolation and property binding. The following binding pairs do the same thing:

Interpolated: <img src="{{vehicle.imageUrl}}"><br>
Property bound: <img [src]="vehicle.imageUrl">

The interpolated title is {{title}}

[innerHTML]="'The [innerHTML] title is '+title">

Interpolation is a convenient alternative for property binding in many cases. In fact, Angular translates those interpolations into the corresponding property bindings before rendering the view.

There is no technical reason to prefer one form to the other. We lean toward readability, which tends to favor interpolation. We suggest establishing coding style rules and choosing the form that both conforms to the rules and feels most natural for the task at hand.

Source: https://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-binding

So you can use anyone. Hope this will help you.

like image 177
Avnesh Shakya Avatar answered Oct 16 '22 08:10

Avnesh Shakya