如何在角度6中分别检查每个查询参数

时间:2019-03-22 06:24:39

标签: angular angular-ui-router angular6

我在处理我的角度应用程序中的查询参数时遇到了问题。我的搜索页面中有多个查询参数。下面是网址

  

/ search?q = hyderbard&view = map&type = bat&brand = sg

const urlParams = Observable.combineLatest(
      this.route.params,
      this.route.queryParams,
      (params, queryParams) => ({ ...params, ...queryParams })
);
urlParams.subscribe(routeParams => {
     routeParams.q !== undefined ? (this.q = routeParams.q): (this.q = "Bangalore");
     routeParams.type !== undefined ? (this.type = routeParams.type): (this.type = "All");
     routeParams.view !== undefined ? (this.view = routeParams.view): (this.type = "list");
     // this will call search api
     this.getList();
});

这是我的代码,因此只要更改查询参数,就会调用getList。 我不希望在更新视图查询参数时调用getList。这该怎么做?谁能帮忙

1 个答案:

答案 0 :(得分:0)

urlParams.pipe(
 tap((routeParams) => {
  routeParams.q !== undefined ? (this.q = routeParams.q): (this.q = "Bangalore");
  routeParams.type !== undefined ? (this.type = routeParams.type): (this.type = "All");
  routeParams.view !== undefined ? (this.view = routeParams.view): (this.type = "list");   
 }),
 map((routeParams) => {
   const {view, ...rest} = routeParams;
   return rest;
 }),
 distinctUntilChanged((prevParams, curParams) => JSON.stringify(prevParams) === JSON.stringify(curParams))
).subscribe(() => {
     this.getList();
});

应该这样做