Building Attribute Directives
@Directive({
selector: '[appHighlight]',
standalone: true
})
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'var(--accent-soft)';
}
}
Learn how to build custom attribute and structural directives in Angular to decouple DOM manipulations from your components.
@Directive({
selector: '[appHighlight]',
standalone: true
})
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'var(--accent-soft)';
}
}