I am new to typescript, and I get this error
Type 'Observable' is not assignable to type 'IProduct[]'. Property 'includes' is missing in type 'Observable'.
My service class is :
getProducts() : Observable<IProduct[]> {
return this._http.get<IProduct[]>(this._productUrl)
.do(data=>console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(err : HttpErrorResponse){
console.log(err.message);
return Observable.throw(err.message)
}
Where is it wrong and what should I do to fix it?
If this question comes from the Angular course on Pluralsight by @DeborahKurata, the answer is in the next module, "Subscribing to an Observable".
In the ngOnInit(): void
method in product-list.component.ts, change this
this.products = this._productService.getProducts();
this.filteredProducts = this.products;
to
this._productService.getProducts()
.subscribe(products => {
this.products = products;
this.filteredProducts = this.products;
}, error => this.errorMessage = <any>error);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With