如何解决我正在尝试使用查询参数基于2个过滤器进行路由,但是只有1个有效
我正在尝试根据类别和大小进行路由,路由网址会更改,但仅基于第二个过滤器进行路由,即侧面过滤器在第一个过滤器中单击,即按类别,它会更改网址,但不会路由
Filter 1 based on category doesnt work
filter 2 based on size works and changes in buttons
app.component.ts
private populateProduct(){
this.productService
.getAll()
.switchMap(products => {
this.products = products;
return this.route.queryParamMap;
})
.subscribe(params => {
this.category = params.get('category')
this.applyFilter()
this.size = params.get('size')
this.sizefilter(); ====> Only thse size filter works
})
}
private applyFilter() {
this.filteredProducts = (this.category) ?
this.products.filter(p => p.category === this.category) :
this.products;
}
private sizefilter(){
this.filteredProducts = (this.size) ?
this.products.filter(p => p.size === this.size) :
this.products;
}
解决方法
您的populateProduct()
函数首先调用applyFilter()
,然后调用this.sizeFilter()
。应用了类别过滤器,但是在调用大小过滤器之后,仅应用了大小过滤器。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。