我开发了一个角度5和Ionic 3 app.I使用以下tuitorial。
但是,我收到了以下错误
错误是:'void'类型中不存在属性'map'。
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)));
}
}
答案 0 :(得分:1)
你错过了a)
.do((res : Response ) => console.log(res.json()))
最后,要阅读httpClient的完整响应,必须明确地观察它:
答案 1 :(得分:0)
再次检查是否从有角而不是从Selenium中导入了HttpClient模块。 做这个。
import { HttpClient } from '@angular/common/http';