Store
Store is observable object that holds all application state
@Component({
selector: 'my-app',
template: `
<div>todos: {{ (todos | async)?.getIn([0]) }}</div>
`
})
class MyAppComponent {
todos: Observable<number>;
constructor(private store: Store<AppState>){
this.todos = store.select(['todos']);
}
}@Component({
selector: 'my-app',
template: `
<div>todos: {{ todos.getIn([0]) }}</div>
`
})
class MyAppComponent {
todos: Map<any, any>;
subscription: Rx.Subscription;
constructor(private store: Store<AppState>, cd: ChangeDetectorRef) implements OnDestroy {
this.subscription = store.select(['todos'])
.subscribe(state => {
this.todos = state; // OR this.todos = state.toJS()
cd.markForCheck();
});
}
ngOnDestroy(){
this.subscription.unsubscribe();
}
}Last updated