Directives
Directives are used to add behavior to elements in the DOM. Here is an example of a directive in Angular:
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[appHighlight]',
})
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'yellow';
}
}
This directive sets the background color of any element with the appHighlight attribute to yellow.
No comments:
Post a Comment