Converting Angular 1 to Angular 2 ngInit function

前端 未结 3 1739
感动是毒
感动是毒 2021-01-07 05:35

In angular1, we call the function ng-init based on ng-if condition. The following code represents If first div match with date && time then it will check the second

3条回答
  •  孤城傲影
    2021-01-07 06:04

    Working code,

    Custom directive:

    import { Directive, Input } from '@angular/core';
    
    @Directive({ selector: '[myCondition]' })
    
    export class ngInitDirective {
      constructor() { }
    
    
      @Input() set myCondition(condition: boolean) {
        if (!condition) {
          console.log("hello")
        } else {
          console.log("hi")
        }
      }
    }
    

    In template:

    
              
    Play
    pause

提交回复
热议问题