import { Directive , Input } from '@angular/core' ; import { TemplateRef , ViewContainerRef } from '@angular/core' ; @ Directive ( { selector : '[dbIf]' } ) export class IfDirective { constructor ( private templateRef , private viewContainer ) { } @ Input ( ) set dbIf ( condition ) { if ( condition ) { this . viewContainer . createEmbeddedView ( this . templateRef ) ; } else { this . viewContainer . clear ( ) ; } } }