简体   繁体   中英

Property 'map' does not exist on type 'void'. in angular

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


}

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM