mobxjs / mobx-angular

The MobX connector for Angular.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It seems like mobxAutorun does not work correctly when it contains an ngIf that changes value

rezoled opened this issue · comments

Reproduction:
https://stackblitz.com/edit/angular-pn2pgd

When you place an ngIf that changes the render result inside an mobxAutorun tag it breaks the mobxAutorun context and MobX assumes that everything inside the ngIf runs outside of an action/reaction

In the reproduction click the button and notice the errors in the console from MobX trace

Inside *mobxAutorun all changeable props must be marked as @observable (show in your case) and to change it, you have to call the method with @action (so it's better to create method inside Component, and don't change it from template). Also when you have any @observable's you have to call makeObservable(this); inside constructor