簡體   English   中英

屬性“ map”在類型“ void”上不存在。 在角度

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

我開發了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)));
}


}

您缺少)

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

最后,要從httpClient讀取完整響應,必須明確觀察它:

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

再次檢查是否從angular而不是Selenium導入了HttpClient模塊。 做這個。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM