Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'includes' is missing in type 'Observable<IProduct[]>'

Tags:

angular

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?

like image 723
user2004 Avatar asked Aug 28 '17 08:08

user2004


1 Answers

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);
like image 58
K0D4 Avatar answered Oct 09 '22 10:10

K0D4