作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在学习 Angular 和 RxJS 运算符。我正在使用 Hearthstone API 来训练它。我究竟做错了什么 ?我想过滤流以仅返回“萨满”卡。我知道,Api 让我有机会按类(class)获得卡片,但我只想训练 RxJS,所以我正在考虑这个问题。我的 ts 组件:
cards: Card[];
ngOnInit() {
this.cardsService.getCards().pipe(
filter((el: any) => el.playerClass === 'Shaman')
).subscribe(res =>
this.cards = res);
}
这是我的服务:
export class CardsService {
constructor(private http: HttpClient) {
}
getCards(): Observable<Card[]> {
const headers = new HttpHeaders().set('X-RapidAPI-Key', '78976c5326mshb1a81046ad68d52p11b362jsn35ec089dd9db');
return this.http.get<Card[]>('https://omgvamp-hearthstone-v1.p.rapidapi.com/cards/sets/Basic', { headers });
}
}
最佳答案
如果您的可观察流返回类型是一个数组,那么流中的项目就是数组。过滤器管道运算符将过滤流中的项目。您的问题来自将任何类型放在过滤器输入上 - 删除并且它应该是 card[] 类型。然后您尝试从数组中提取一个属性。
关于angular - 我做错了什么 RxJS 运营商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54776308/
我是一名优秀的程序员,十分优秀!