Loading.dismiss() not working


#1

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

@Injectable()
 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...'
          });
          loading.present();
         return this.http
             .get(this._postsURL)
             .map((response: Response) => {
                loading.dismiss();
                console.log("Result printed!!");
                 return <IPosts[]>response.json();
                 
             })
             .catch(this.handleError);

             
     }
 
      handleError(error: Response) {
          this.loading.dismiss();
         console.log("Err printed!!" + error.statusText);
         return Observable.throw(error.statusText);
     }
 }