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

后端 未结 3 1973
孤独总比滥情好
孤独总比滥情好 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:00

    Important notice - Short way in subjects can makes problem!

    I know it's not exactly what the PO asked, but there is sometimes very common problem that can happen, and maybe it will be helpful for someone.

    It's very simple, and also I didn't inspect the issue deeply.

    But in my case the problem was that I have used in short syntax for subscribe the subject to observable instead of full, and when I have changed it, it solved the issue.

    So While this didn't work :

    myServiceObservableCall.subscribe(this.myBehavSubj)
    

    and with the same behavior that on log I am seeing the changes properly, only on the view not.

    This does update the view :

    myServiceObservableCall.subscribe((res)=>{
            this.myBehavSubj.next(res);
          } );
    

    Although it's seems to be the same and the above only short-way syntax .

    You are invited to explain the reason

提交回复
热议问题