import { Directive , ElementRef , AfterViewInit } from '@angular/core' ; import { CodeHighlightService } from './code-highlight.service' ; import { FeaturesService } from '../../services/features.service' ; example author Jim Toth <jim@meme.coach>
  @ Directive ( { selector : '[m-code-highlight]' , } ) export class CodeHighlightDirective implements AfterViewInit { constructor ( private element , private codeHighlightService , private featuresService ) { } ngAfterViewInit ( ) { if ( ! this . featuresService . has ( 'code-highlight' ) ) { return ; } this . highlightBlocks ( this . element . nativeElement . querySelectorAll ( 'pre > code' ) ) ; } highlightBlocks ( blocks ) { for ( let i = 0 ; i < blocks . length ; i ++ ) { this . codeHighlightService . highlightBlock ( blocks [ i ] ) ; } } }