角度方法参数奇怪的行为

时间:2018-03-30 00:49:47

标签: javascript angular

我有一个带有子组件(模态)的简单组件。

parentComponent.ts

onShowModal($e) {
     chrome.runtime.sendMessage(AppConsts.chromeExtension.id, {}, (reply) => 
            { 
                const isInstalled = reply ? true : false; // here is true
                this._service.getById(id) 
                    .subscribe(response => {
                        this.customModal.show($e, response, isInstalled);
                    });
           });
 }

customModalComponent.ts

  // Component Code
  isExtensionInstalled = false;

   show(event, response, isInstalled: boolean) {
      this.isExtensionInstalled = isInstalled;
      this.response = response;
      this.event = event;

      this.modal.show(); //Here the modal appears on the screen, but the `this.isExtensionInstalled` variable stays as false for a while, then it changes to true (after some milliseconds);
  }

问题在于,当我执行onShowModal方法时,isInstalled常量为真,因此true是isInstalled参数。但是当模态实际出现在屏幕上时,isExtensionInstalled会暂时保持为假,然后它会更改为参数中传递的正确值(true)。

为什么会这样?

0 个答案:

没有答案