directives angular code example
Example 1: angular directive output
@Output() itch:EventEmitter<any> = new EventEmitter();
<div appCollar (itch)='scratch()' >
Example 2: angular directive
ng generate directive highlight
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[appHighlight]'
})
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'yellow';
}
}
<p appHighlight> highlighted text </p>
Example 3: user defined directives in angular 7
import { Directive, ElementRef } from '@angular/core';
Example 4: angular directive
content_copy
<p app:Highlight>This is invalid</p>
Example 5: user defined directives in angular 7
<p [ngStyle]="{`THE CSS YOPU WANT TO ADD`}"> I am an Attribute Directive</p>
Example 6: change specific element style angular directive
content_copy
ng generate directive highlight