IonicCache + HttpClient (Angular 4.4)


#1

Hello everyone,

Before updating to angular 4.4 ,I was using IonicCache like this example : https://ionicacademy.com/ionic-caching-service/

Now, I upgrade to Angular 4.4 and upgrade other dependencies too. I needed to use the new HttpClient and HttpInterceptor to put default header in request.

The angular document, said that we can use interceptor to cache request (https://angular.io/guide/http#caching), but I wanted to continue use IonicCache.

I did some modification so :

 let req = this.http.get(this.url);
     req.subscribe(resp => {
       console.log(resp);
       this.currentCategories = this.cache.loadFromObservable(this.url,req,this.key);
     },
     err => {
       console.log(err);
     }

I get 'Runtime Error : Uncaught (in promise) : no suck key for “my_api_url”

Can I continue to use IonicCache with new HttpClient ? Or should I use Interceptor to cache request ?
=> this.http.get : return an observable needed for “loadFromObservable”

thanks for any advice