0
votes

I develop a angular 5 and Ionic 3 app.I use following tuitorial.

https://www.techiediaries.com/ionic-3-http-module-rxjs/

But,I got following error

error is : Property 'map' does not exist on type 'void'.

My Code ( file : remote-service.ts)

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import {Http ,Response } from '@angular/http';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

/*
  Generated class for the RemoteServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class RemoteService {

getApiUrl : string = "https://jsonplaceholder.typicode.com/posts";

  constructor(public http: HttpClient) {
    console.log('Hello RemoteServiceProvider Provider');
  }

  getPosts() {

    return  this.http.get(this.getApiUrl)
            .do((res : Response ) => console.log(res.json())
            .map((res : Response ) => res.json())  // <-- error shows here
            .catch(error => console.log(error)));
}


}
2

2 Answers

1
votes

You are missing a )

.do((res : Response ) => console.log(res.json()))

Finally, to read the full response from httpClient it has to be observed explicitly:

https://angular.io/guide/http#reading-the-full-response

0
votes

Check again that you imported HttpClient module from angular and not Selenium. Do this.

import { HttpClient } from '@angular/common/http';