Skip to content
Angular Essentials
GitHub

Attribute directives

Attribute directives listen to and modify the behavior of other HTML elements, attributes, properties, and components.

Adding and removing classes with NgClass

...
<p [ngClass]="isSpecial ? 'special' : ''">I am {{'running'}} on port {{port}}</p>
...
...
isSpecial: boolean = true;
...
.special {
  color: deeppink;
}

Task for yourself

  • NgSwitch
  • NgStyle

Refer here.