如何从 ngrx-store 获取对象
How can I get an object from ngrx-store
如何从 ngrx-store 获取对象?
我正在尝试这样做
<div class="container">
<h1>
{{category$.name}}
</h1>
</div>
组件
export class CatalogViewController {
private routeSubscription: Subscription;
private uri: string;
category$: Observable<any>;
constructor(
private store: Store<fromRoot.State>,
private route: ActivatedRoute,
private router: Router,
private titleService: Title
) {
this.routeSubscription = route.params.subscribe(params=>this.uri = params['uri']);
this.store.dispatch(new catalogActions.LoadCategory({"uri": this.uri}));
this.category$ = store.select(fromRoot.getCategory);
}
}
商店中的数据可用
商店
catalog: {
category: {
name: 'Phones',
uri: 'phones',
__typename: 'Category'
}
}
一个简单的情况,但我不明白我做错了什么:D
就这样
<div class="container">
<h1>
{{(category$ | async)?.name}}
</h1>
</div>
如何从 ngrx-store 获取对象?
我正在尝试这样做
<div class="container">
<h1>
{{category$.name}}
</h1>
</div>
组件
export class CatalogViewController {
private routeSubscription: Subscription;
private uri: string;
category$: Observable<any>;
constructor(
private store: Store<fromRoot.State>,
private route: ActivatedRoute,
private router: Router,
private titleService: Title
) {
this.routeSubscription = route.params.subscribe(params=>this.uri = params['uri']);
this.store.dispatch(new catalogActions.LoadCategory({"uri": this.uri}));
this.category$ = store.select(fromRoot.getCategory);
}
}
商店中的数据可用
商店
catalog: {
category: {
name: 'Phones',
uri: 'phones',
__typename: 'Category'
}
}
一个简单的情况,但我不明白我做错了什么:D
就这样
<div class="container">
<h1>
{{(category$ | async)?.name}}
</h1>
</div>