Directive

Directives in Angular are used to manipulate the DOM and apply custom behavior.

Snippet:

@Directive({ selector: "[appHighlight]" }) export class HighlightDirective { constructor(el: ElementRef) { el.nativeElement.style.backgroundColor = "yellow"; } }

Example:

@Directive({ selector: "[appRedBorder]" }) export class RedBorderDirective { constructor(el: ElementRef) { el.nativeElement.style.border = "2px solid red"; } }