Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在调度一个操作以分派第二个操作后等待一个存储完成_Angular_Rxjs_Ngrx - Fatal编程技术网

Angular 如何在调度一个操作以分派第二个操作后等待一个存储完成

Angular 如何在调度一个操作以分派第二个操作后等待一个存储完成,angular,rxjs,ngrx,Angular,Rxjs,Ngrx,我有一个与我的组件相关的init数据存储,这个数据的一个例子是一个带有apiPath的字符串 ngOnInit() { // this store contains data related to the component this.store.dispatch(this.searchActions.addPageData(this.pageData)); } 然后,我有另一个操作,它需要来自上一个存储的数据,并在路由参数发生更改时触发: this.ro

我有一个与我的组件相关的init数据存储,这个数据的一个例子是一个带有apiPath的字符串

   ngOnInit() {
       // this store contains data related to the component
       this.store.dispatch(this.searchActions.addPageData(this.pageData));
  }
然后,我有另一个操作,它需要来自上一个存储的数据,并在路由参数发生更改时触发:

this.route.params.subscribe((params: Params) => {
    this.store.dispatch(this.searchActions.routerParamsSearchPageChanged(pageFilters));
})

如何等待第一个操作填充存储,然后分派第二个操作。

我假设第一个操作(addPageData)用一些信息填充存储。然后,您想使用route参数过滤掉数据,猜测某种类型的查询?如果这个查询不适合您的需要,也许您可以再详细说明一下

基本上,检索所需的存储信息和查询参数。通过某种类型的条件过滤该查询,这可能只是简单地检查
null
以确保数据存在

 Observable.combineLatest(
        this.store.select(state => state.bookState),
        this.route.params.select<string>('query')
    )
    .filter(([bookState]) => bookState.books !== null)
    .subscribe(([books, query]) => {
        this.store.dispatch({
            type: '[Books] FILTER_BY_QUERY', 
            payload: {
                bookType: books.type,
                query: query
            }
        });
    });
Observable.combinelatetest(
this.store.select(state=>state.bookState),
this.route.params.select('query')
)
.filter(([bookState])=>bookState.books!==null)
.订阅(([书籍,查询])=>{
这是我的商店({
类型:“[Books]按查询筛选”,
有效载荷:{
bookType:books.type,
查询:查询
}
});
});

我认为这可能与此有关:,@chrigu我的第二次调度,当路由更改时,需要来自另一个存储的信息,因此CombineTest不起作用,因为我需要它们同步而不是异步且并行。尝试此方法您可以关联它