I have angular app v6 and I'm using latest version of mobx
and mobx-angular
(You can see in dependency). I'm coming from ngrx, ngxs background so it is tough to understand mobx flow because it more or less angular-service
approach with something extra (with performance also).
I have few question asked in stackblitz example. I hope somebody to give guidance on them.
store.ts
@Injectable()
export class Store {
@observable counter: number = 0;
constructor() { }
@action count() {
this.counter ++;
}
}
app.component.ts
export class AppComponent {
_counter:number=0;
constructor(private store:Store){}
ngOnInit(){
// how to subscribe to updated value of counter from service and assign it to this._counter ????
this._counter = this.store.counter;
}
}
app.component.html
<div *mobxAutorun>Counter : {{store.counter}}<br /></div>
______________________________________________
<div>Counter : {{store.counter}}<br /></div>
______________________________________________
<div>how to subscribe to updated value form 'counter' variable to '_counter' local variable????</div><br />
<div> {{_counter}} </div>
<button (click)="store.count()">Count</button>