Angular 6 View is not updated after changing a variable within subscribe

后端 未结 3 1979
孤独总比滥情好
孤独总比滥情好 2020-12-01 07:37

Why is the view not being updated when a variable changes within a subscribe?

I have this code:

example.component.ts

testVar         


        
3条回答
  •  一个人的身影
    2020-12-01 08:05

    For me none of the above worked. However, ChangeDetectorRef did the trick.

    From angular Docs where is how it is implemented:

        class GiantList {
          constructor(private ref: ChangeDetectorRef, public dataProvider: DataListProvider) {
            ref.detach();
            setInterval(() => { this.ref.detectChanges(); }, 5000);
          }
        }
    
    

    https://angular.io/api/core/ChangeDetectorRef

提交回复
热议问题