⊗jsagPmLpRc 41 of 97 menu

Reactivity in Angular

Whenever public properties change, the template will react reactively, i.e. change instantly. This is how reactivity works in Angular.

Let's look at an example. Let's say we have a property that contains text:

export class AppComponent { public text: string = ''; }

Let's display our property in some tag:

<div> {{ text }} </div>

Now let's make a button that, when clicked, will call the class method:

<button (click)="show()"> show </button>

In this method we will change the text:

export class AppComponent { public text: string = ''; public show(): void { this.text = 'hello'; } }

Now, if you run the code and click on the button, the text in the div will change immediately after clicking.

Make a div and two buttons. Make it so that when you click the first button, one text gets into the div, and when you click the second button, another text gets into the div.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline