ngIf not detecting var change

前端 未结 1 1107
耶瑟儿~
耶瑟儿~ 2020-12-15 11:03

I am using the greensock animation library to animate some components (as you would expect). I am experiencing an issue when I am updating a variable in the o

相关标签:
1条回答
  • 2020-12-15 11:54

    please refer to this Angular 2 documentation: Lifecycle Hooks

    According to the documentation,

    Angular's unidirectional data flow rule forbids updates to the view after it has been composed. Both of these hooks fire after the component's view has been composed.

    Option1: use ngZone.run to notify angular to render the view again.

    // import ngZone from @angular/core first.
    this.ngZone.run(() => {
      console.log("anim complete");
      this.rightVisible = false;
    });
    

    Option2: use ChangeDetector to let angular to render the view again.

    import {ChangeDetector} from '@angular/core';
    
    this.rightVisible = false;
    this.cd.detectChanges();
    

    Refer this plunker that contains the upper code block.

    0 讨论(0)
提交回复
热议问题