Error in observable IONIC 2

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());

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?

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

solved!

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

1 Like

it’s a simple wrong code…

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?

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

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