0

I am new to Angular and was not sure if this is the recommended syntax in Angular. In AngularJS, we can do one-time binding in this way:

<p>{{::myVar}}</p>

In Angular, I know we can do this.

<p [innerText]="myVar"></p>

My first question is, is this the only way to achieve {{::}} in Angular?

What if I have this situation in AngularJS:

<p>{{::myVar}} is a variable</p>

I have tried something like this

<p [innerText]="myVar + 'is a variable'"></p>

It works but again is this the recommended syntax?

Charlie Ng
  • 640
  • 5
  • 11

1 Answers1

0

in angular there are three ways of one way data biding from the component to the template:

  • Interpolation {{myVar}} => recommended use case: <p>{{myVar}} is a variable</p>
  • Property binding [attri]="url" => <img [src]="url">
  • bind-target="myVar"

EDIT: one time binding on the other hand is a feature we used to have in angular 1 and you can replicate it in angular using ChangeDetectionStrategy.CheckOnce

check the official docs here

Hamed Baatour
  • 6,664
  • 3
  • 35
  • 47