What are directives?

Directives add behaviour to an existing DOM element or an existing component instance.

import { Directive, ElementRef, Input } from '@angular/core';
@Directive({ selector: '[myHighlight]' })
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'yellow';
}
}

Now this directive extends HTML element behavior with a yellow background as below

<p myHighlight>Highlight me!</p>

Author of content
Edit this page

Made by Michael Sakhniuk

Twitter