Answers for "directives in angular"

3

angular directive

//generate Angular Directives
ng generate directive highlight

//it will generate the following component
import { Directive, ElementRef } from '@angular/core';

@Directive({
  selector: '[appHighlight]'
})
export class HighlightDirective {
    constructor(el: ElementRef) {
       el.nativeElement.style.backgroundColor = 'yellow';
    }
}
// you can use the directive in the template as:
<p appHighlight> highlighted text </p>
Posted by: Guest on February-10-2021
0

directives in angular

content_copy
      
      <!-- toggle the "special" class on/off with a property -->
<div [ngClass]="isSpecial ? 'special' : ''">This div is special</div>
Posted by: Guest on September-30-2021

Code answers related to "directives in angular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language