Loading.dismiss() not working

I am trying to do loading.dismiss() inside handleError() method , but not sure how to do? it is perfectly working while the response is good, not sure how to handle error case

please help

 export class SharedProvider {
     private _postsURL = "https://jsonplaceholder.typicode.com/posts";
     constructor(private http: Http, public loadingCtrl: LoadingController) {

     getPosts(): Observable<IPosts[]> {

        let loading = this.loadingCtrl.create({
            content: 'loading...'
         return this.http
             .map((response: Response) => {
                console.log("Result printed!!");
                 return <IPosts[]>response.json();

      handleError(error: Response) {
         console.log("Err printed!!" + error.statusText);
         return Observable.throw(error.statusText);
1 Like