O'Reilly logo

Learning Angular, 2nd Edition by Caleb Dayley, Brendan Dayley, Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8Custom Directives

As with many other features of Angular, you can extend functionality by creating your own custom directives. Custom directives allow you to extend the functionality of HTML by implementing the behavior of elements yourself. If you have code that needs to manipulate the DOM, it should be done inside a custom directive.

You implement a custom directive by calling the @directive class, much the same way you define a component. The @directive class metadata should include the selector of the directive to be used in the HTML. The Directive export class is where the logic for the directive will reside. For example, the following is a basic definition for a directive:

import { Directive } from '@angular/core'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required