【发布时间】:2018-09-01 22:29:31
【问题描述】:
我开发了一个 Angular 5 和 Ionic 3 应用程序。我使用以下教程。
但是,我得到以下错误
错误是:“void”类型上不存在属性“map”。
我的代码(文件: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)));
}
}
【问题讨论】:
标签: angularjs typescript ionic-framework ionic3