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>

Made in India with ❤️ by Rajesh Kumar Yadav