Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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 以正确的方式使用rxjs withLatestFrom_Angular_Rxjs - Fatal编程技术网

Angular 以正确的方式使用rxjs withLatestFrom

Angular 以正确的方式使用rxjs withLatestFrom,angular,rxjs,Angular,Rxjs,我有两页(第X页和第Y页)。它们都共享相同的组件和解析器 在共享组件的ngOnInit()中,我使用route.queryParams和route.data: constructor( private route: ActivatedRoute, ) { } ngOnInit(): void { this.route.queryParams.pipe( withLatestFrom(this.route.data), map(([qp, data]: [Params,

我有两页(第X页和第Y页)。它们都共享相同的组件和解析器

在共享组件的
ngOnInit()
中,我使用
route.queryParams
route.data

constructor(
  private route: ActivatedRoute,
) { }

ngOnInit(): void {
  this.route.queryParams.pipe(
    withLatestFrom(this.route.data),
    map(([qp, data]: [Params, Data]) => {

    }),
  );
}
另外,请注意,对于我在
路由
中定义的两个页面:
runguard和resolvers:'paramsOrQueryParamsChange'
。这意味着,在共享同一组件的页面之间导航时,解析程序也将被激活

现在-问题是当我从X页导航到Y页或反之亦然。 问题在于
withLatestFrom
。 当我移动到第二页时,我在
映射(([qp,data]:[Params,data])=>{…})中得到的
数据
等于解析程序为进入第一页提供的数据——但我需要解析程序为第二页提供的数据


如何修复它?

看起来像
此.route.queryParams
在路由更改时发出
此.route.data
之前发出。如果要在上次发射后发射两个观测值,请使用
zip

zip(this.route.queryParams,this.route.data).pipe(
映射([qp,数据]:[Params,data])=>{
}),
);

看起来像
this.route.queryParams
在路由更改时发出
this.route.data
之前发出。如果要在上次发射后发射两个观测值,请使用
zip

zip(this.route.queryParams,this.route.data).pipe(
映射([qp,数据]:[Params,data])=>{
}),
);