【发布时间】:2019-02-19 23:08:59
【问题描述】:
我正在学习 Angular 和 RxJS 运算符。我正在使用炉石 API 来训练它。我究竟做错了什么 ?我想过滤流以仅返回“萨满”卡。我知道,Api 让我有机会按类获得卡片,但我只想训练 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 });
}
}
【问题讨论】: