puddlejumper26 / blogs

Personal Tech Blogs
4 stars 1 forks source link

Data Binding in Angular #56

Open puddlejumper26 opened 4 years ago

puddlejumper26 commented 4 years ago

Property

e.g. src, hero, and ngClass in the following

<img [src]="heroImageUrl">
<app-hero-detail [hero]="currentHero"></app-hero-detail>
<div [ngClass]="{'special': isSpecial}"></div>

Event

e.g. click, deleteRequest, and myClick in the following

<button (click)="onSave()">Save</button>
<app-hero-detail (deleteRequest)="deleteHero()"></app-hero-detail>
<div (myClick)="clicked=$event" clickable>click me</div>

Two-way

e.g.

<input [(ngModel)]="name">

Here needs to import FormsModule in the Module.

Attribute

-Attribute

e.g.

<button [attr.aria-label]="help">help</button>

Class

e.g.

<div [class.special]="isSpecial">Special</div>

Style

e.g.

<button [style.color]="isSpecial ? 'red' : 'green'">

Reference

[1] https://angular.io/guide/template-syntax#binding-types-and-targets