MyInternships.in

Directives, Pipes & Templates

Angular Directives Overview

A directive is a class that changes the appearance or behaviour of an element. Angular has three kinds: components (directives with a template), structural directives that add or remove DOM, and attribute directives that modify an existing element.


What is Directives Overview in Angular?

A directive is a class that changes the appearance or behaviour of an element. Angular has three kinds: components (directives with a template), structural directives that add or remove DOM, and attribute directives that modify an existing element.

Key points to remember

  • Structural directives change the DOM tree; attribute directives change an existing element.
  • From Angular 17 the built-in control flow — @if, @for, @switch — replaces the *ng equivalents.
  • A custom directive is generated with ng g directive name.

The three directive types

TypeMarked withExamples
Component@Componentevery component you write
Structural* prefix or @if / @for*ngIf, *ngFor, *ngSwitch, @if, @for
Attributeplain attributengClass, ngStyle, ngModel, your own

Angular Directives Overview— Interview Questions & FAQs

What is the difference between a structural and an attribute directive?+

A structural directive adds or removes elements from the DOM — the asterisk is a hint that a template is being created. An attribute directive changes the look or behaviour of an element that already exists.

Related Angular Topics

Keep learning with these closely related lessons.

Ready to use your Angular skills?

Find verified Angular internships and fresher developer jobs across India.

Browse Angular Internships