xxxxxxxxxx
import { Directive, ElementRef, Input, OnInit } from '@angular/core'
@Directive({
selector: '[ttClass]',
})
export class ttClassDirective implements OnInit {
@Input() ttClass: string;
constructor(private el: ElementRef) {
}
ngOnInit() {
this.el.nativeElement.classList.add(this.ttClass);
}
}
xxxxxxxxxx
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[appHighlight]'
})
export class HighlightDirective {
constructor(private el: ElementRef) {
this.el.nativeElement.style.backgroundColor = 'yellow';
}
}
//To create a directive, use the CLI command
//ng g directive <name> [options]