Takes the Angular Heroes and added a column of rating to it. The ratings contains values like good, very good, poor
Trying to take advantage of RxJS, filter operator to do this. When looking at https://www.learnrxjs.io/learn-rxjs/operators/filtering/filter example 2 it seems to be what I want
// RxJS v6+
import { from } from 'rxjs';
import { filter } from 'rxjs/operators';
//emit ({name: 'Joe', age: 31}, {name: 'Bob', age:25})
const source = from([
{ name: 'Joe', age: 31 },
{ name: 'Bob', age: 25 }
]);
//filter out people with age under 30
const example = source.pipe(filter(person => person.age >= 30));
//output: "Over 30: Joe"
const subscribe = example.subscribe(val => console.log(`Over 30: ${val.name}`));
however when using httpclient it does not work and has an error of "Property 'rating' does not exist on type 'Hero[]'.ts(2339)"
isVeryGoodAd(): Observable<Hero[]> {
return this.http.get<Hero[]>(this.heroesUrl).pipe(
filter(heroes => heroes.rating === 'verygood')
)
;
}
How to use httpclient with RxJS filter to remove the unwanted values while returning an Observable which I would be able to subscribe to?