简体   繁体   中英

Angular 2 html directives and attribute directives

I'm new to Angular 2.

Can someone please explain the difference between the html directives and attribute directives ? Why are they both needed?

Example:

<rating [rate]="rate" (rate-change)="onUpdate($event)"></rating>

So:

rating is what i call "html directive" but I'm not sure what it's for?

[rate] is an attribute directive that sets component property named "rate".

(rate-change) is an attribute directive that calls a component method called rateChange .

Any other types of directives ?

html directives are for managing dom elements like creating elements. attribute directives modify properties of elements. so angular could create several divs, then later change a div's text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM