mobxjs / mobx-angular

The MobX connector for Angular.
MIT License
483 stars 59 forks source link

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

Closed rezoled closed 1 year ago

rezoled commented 1 year ago

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

YugasVasyl commented 1 year ago

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