简体   繁体   English

属性“ map”在类型“ void”上不存在。 在角度

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

I develop a angular 5 and Ionic 3 app.I use following tuitorial. 我开发了angular 5和Ionic 3应用程序。我使用以下教程。

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

But,I got following error 但是,我收到以下错误

error is : Property 'map' does not exist on type 'void'. 错误是:类型“ void”上不存在属性“ map”。

My Code ( file : remote-service.ts) 我的代码(文件: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)));
}


}

You are missing a ) 您缺少)

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

Finally, to read the full response from httpClient it has to be observed explicitly: 最后,要从httpClient读取完整响应,必须明确观察它:

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

Check again that you imported HttpClient module from angular and not Selenium. 再次检查是否从angular而不是Selenium导入了HttpClient模块。 Do this. 做这个。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度可观察响应中不存在属性映射 - property map does not exist on observable response in angular “可观察”类型上不存在属性“地图”<book[]> '</book[]> - Property 'map' does not exist on type 'Observable<Book[]>' 错误TS2339:类型“无效”上不存在属性“ _ws” - error TS2339: Property '_ws' does not exist on type 'void' 类型&#39;($ router:any)=&gt; void&#39;上不存在属性&#39;$ routeConfig&#39; - Property '$routeConfig' does not exist on type '($router: any) => void' &#39;EventTarget&#39;类型上不存在Angular属性&#39;parentNode&#39; - Angular property 'parentNode' does not exist on type 'EventTarget' Angular2 NavigationEnd 事件的“事件”类型上不存在属性“url” - Property 'url' does not exist on type 'Event' for Angular2 NavigationEnd Event 类型“#”错误中不存在属性“#” - Property "#" does not exist on type "#" error 属性“ requestOptions”在类型上不存在 - Property 'requestOptions' does not exist on type 使用Ionic2和Angular2的类型&#39;Navigator&#39;上不存在属性&#39;connection&#39; - Property 'connection' does not exist on type 'Navigator' using Ionic2 and Angular2 使用 firebase 7.14.6 和 @angular/fire 6.0.0 FCM web 推送通知的类型“AngularFireMessaging”上不存在属性“消息” - Property 'messaging' does not exist on type 'AngularFireMessaging' using firebase 7.14.6 and @angular/fire 6.0.0 FCM web push notification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM