[英]Property 'map' does not exist on type 'void'. in angular
我开发了angular 5和Ionic 3应用程序。我使用以下教程。
但是,我收到以下错误
错误是:类型“ 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)));
}
}
您缺少)
.do((res : Response ) => console.log(res.json()))
最后,要从httpClient读取完整响应,必须明确观察它:
再次检查是否从angular而不是Selenium导入了HttpClient模块。 做这个。
import { HttpClient } from '@angular/common/http';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.