Error in observable IONIC 2


#1
import {Injectable} from '@angular/core';
import {Http, Response} from "@angular/http";
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/catch';
import 'rxjs/Rx';

Typescript Error
Property ‘cache’ does not exist on type ‘Observable’.
C:/xampp/htdocs/PedidosJa/src/app/service.ts

return this.http.get('assets/json/restaurantAppJson.json')
    .cache()
.map((response: Response) => response.json());

#2

Seems pretty self-explanatory. Property 'cache' does not exist on type 'Observable'. Means that it doesn’t know the ‘cache’ method your calling on the Observable. Did you verify you can use it in this specific way?


#3
getData() {
        return this.http.get('assets/json/restaurantAppJson.json')
            .toPromise()
            .then((response: Response) => response.json());
    }

solved!


#4

What was that .cache() meant for if you solve it like you’re doing now?


#5

it’s a simple wrong code…


#6

Ah okay. Do you mind if I ask why you’re doing toPromise, since this.htpp.get returns an observable which you could describe to?


#7

I suspect this was all just a misspelling, because OP imported “catch”, which tells me that’s what they intended to use as “cache”.


#8

Thought the same thing, but catch is something entirely different so I dropped the thought :smiley: