Angular 4 - “Expression has changed after it was checked” error while using NG-IF

后端 未结 6 1554
天命终不由人
天命终不由人 2020-12-14 21:05

I setup a service to keep track of logged in users. That service returns an Observable and all components that subscribe to it are notified (so

6条回答
  •  佛祖请我去吃肉
    2020-12-14 21:18

    I recently encountered the same issue after migration to Angular 4.x, a quick solution is to wrap each part of the code which causes the ChangeDetection in setTimeout(() => {}, 0) // notice the 0 it's intentional.

    This way it will push the emit AFTER the life-cycle hook therefore not cause change detection error. While I am aware this is a pretty dirty solution it's a viable quickfix.

提交回复
热议问题