【问题标题】:Property 'map' does not exist on type 'void'. in angular“void”类型上不存在属性“map”。在角度
【发布时间】:2018-09-01 22:29:31
【问题描述】:

我开发了一个 Angular 5 和 Ionic 3 应用程序。我使用以下教程。

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

但是,我得到以下错误

错误是:“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


    【解决方案1】:

    你少了一个)

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

    最后,要从 httpClient 读取完整响应,必须明确观察:

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

    【讨论】:

    【解决方案2】:

    再次检查您是否从 Angular 而不是 Selenium 导入了 HttpClient 模块。 这样做。

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

    【讨论】:

      猜你喜欢
      • 2022-06-28
      • 2017-12-22
      • 2019-12-01
      • 2019-03-18
      • 2018-08-11
      • 2021-08-05
      • 1970-01-01
      • 2018-01-09
      • 2021-08-22
      相关资源
      最近更新 更多