【发布时间】:2016-11-29 17:44:57
【问题描述】:
我正在使用 ngrx 构建一个 ng2 应用程序。当应用程序启动时,会调用 Web 服务来获取初始数据,一旦获取了这些数据,我就会创建一个 INIT_DONE 操作。
我的状态如下所示:
export interface State {
documents: Document[];
selectedDocument: Document
}
当我转到页面 /mypage/456 时,其中 456 是一个 url 参数,我需要获取一些获取的数据,所以我得到这样的 URL 参数:
ngOnInit() {
this.paramSubscription = this.route.params
.select<string>('id')
.map((id) => new SelectAction(id))
.subscribe(this.store);
}
SELECT_ACTION 在获取的数据中找到元素并设置selectedDocument。问题是 SELECT_ACTION 是在 INIT_DONE 之前创建的,此时 documents 为空。
如何在加载我的页面之前等待 INIT_DONE ?
【问题讨论】: