Angular 2 View will not update after variable change in subscribe

后端 未结 4 1669
耶瑟儿~
耶瑟儿~ 2020-11-27 04:26

I have a problem where my view will not change when I update my variable in my observable subscription. I am trying to show a loading spinner while I wait for a response fro

4条回答
  •  一个人的身影
    2020-11-27 04:41

    You can also try this solution: Guide from Thoughtram

    Short version:

     import { ChangeDetectorRef } from '@angular/core';
        ...
        constructor(private cd: ChangeDetectorRef) {}
        ...
        ... .subscribe( () => {
               
               this.cd.markForCheck();
            }
    

    and you are good.

    Background: when changing a value via .subscribe() angular does not notify that it should run changedetection. So you need to run it yourself.

提交回复
热议问题