Directives

 attach
 

custom behavior
 

to elements
 

in the DOM

  • built-in directives
     
  • custom directives

Built-in directives

  • Attribute directives

Modify behavior

  • Structural directives

     Modify DOM structure

Attribute directives

  • NgClass

Add and remove a set of CSS classes

  • NgStyle

Add and remove a set of HTML styles

  • NgModel

Add two-way data binding to an HTML form element

Structural directives

  • NgForOf

Repeat a template for each item in a list

  • NgIf

Conditionally add or remove an element from the DOM

  • NgSwitch

A set of directives that switch among alternative views

 structural directives

are always prefixed

with an *

<p *ngFor="let item of namesList">

        {{i}} - Hello {{item}}!

</p>

Directives

By Enrique Oriol

Directives

  • 48