angular - 如何将 params.get('brand') 分配给以下函数中的变量?
问题描述
我正在尝试将结果分配给map 方法params.get('brand')
中的变量brandName
,但它不起作用。我怎样才能做到这一点?
private getProducts() {
this.products$ = this.route.paramMap.pipe(
map((params:ParamMap) => this.brandName = params.get('brand')),
switchMap((params:ParamMap) =>
this.dataService.getProductsByBrand(params.get('brand')))
)
this.products$.subscribe(products => {
this.setProducts(products);
console.log('products', this.products)
})
}
解决方案
一个工作示例链接会有所帮助。
您可以使用rxjs
'tap
运算符来获得副作用。
例如
this.products$ = this.route.paramMap.pipe(
tap((params:ParamMap) => this.brandName = params.get('brand')),
switchMap((params:ParamMap) =>
this.dataService.getProductsByBrand(params.get('brand')))
)
推荐阅读
- powershell - Powershell 单例数组
- racket - 为什么我的函数返回的列表结果看起来很有趣?
- javascript - 反重力/反重力?我需要更改重力算法的哪些元素才能反转它?
- amazon-s3 - 在 aws 中管理多个服务器中的内存缓存
- haskell - 在 Haskell 中执行 where 子句
- javascript - Leaflet 中有没有办法从 L.easybutton 重置功能?
- input - 如何在 GNU Prolog 中读取用户的一行输入,直到 EOF 被击中?
- google-oauth - C++Builder TWebBrowser 不适用于 Google OAuth 登录
- c# - 如何找到平面大小和位置并在其上生成随机对象?
- javascript - 如何立即更改 DOM 元素?