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'; ...
Get Learning Angular, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.