我有角度应用程序 v6,我正在使用最新版本的mobx
和mobx-angular
(您可以在依赖项中看到)。我来自 ngrx,ngxs 背景,所以很难理解 mobx 流程,因为它或多或少地angular-service
接近了一些额外的东西(也有性能)。
我在 stackblitz 示例中问的问题很少。希望有人指导一下。
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>