directives in angular

Solutions on MaxInterview for directives in angular by the best coders in the world

showing results for - "directives in angular"
Amy
13 May 2017
1//generate Angular Directives
2ng generate directive highlight
3
4//it will generate the following component
5import { Directive, ElementRef } from '@angular/core';
6
7@Directive({
8  selector: '[appHighlight]'
9})
10export class HighlightDirective {
11    constructor(el: ElementRef) {
12       el.nativeElement.style.backgroundColor = 'yellow';
13    }
14}
15// you can use the directive in the template as:
16<p appHighlight> highlighted text </p>
Janna
29 Jan 2018
1      
2        content_copy
3      
4      <!-- toggle the "special" class on/off with a property -->
5<div [ngClass]="isSpecial ? 'special' : ''">This div is special</div>
6