简体   繁体   English

为什么我在Angular应用程序中遇到此错误? 类型“可观察”不存在属性“ toPromise” <Response> “

[英]Why I am obtaining this error in an Angular application? Property 'toPromise' does not exist on type 'Observable<Response>'

I am very new in Angular2/4 and I have some problem trying to follow this tutorial related to PrimeNG : 我是Angular2 / 4的新手,尝试遵循与PrimeNG相关的本教程时遇到一些问题:

https://www.primefaces.org/primeng/#/schedule https://www.primefaces.org/primeng/#/schedule

I created the EventService class into a file in my prohject, in this way: 我通过以下方式将EventService类创建到文件中:

import {Injectable} from '@angular/core';
import {Http} from '@angular/http';

@Injectable()
export class EventService {

  constructor(private http: Http) {}

  getEvents() {
    return this.http.get('showcase/resources/data/scheduleevents.json')
      .toPromise()
      .then(res => <any[]> res.json().data)
      .then(data => { return data; });
  }
}

The problem is that WebStorm give me an error on the toPromise() method, it says: 问题是WebStorm在toPromise()方法上给我一个错误,它说:

Error:(11, 8) TS2339:Property 'toPromise' does not exist on type 'Observable<Response>'.

Why? 为什么? What it means? 这是什么意思? What is the problem? 问题是什么? How can I try to fix it? 我该如何解决?

您需要像这样导入运算符:

import 'rxjs/add/operator/toPromise';

暂无
暂无

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

相关问题 Angular 2:&#39;Observable&#39;类型中不存在属性&#39;toPromise&#39; <Response> “ - Angular 2: Property 'toPromise' does not exist on type 'Observable<Response>' 类型'Observable <Response>'上不存在属性'toPromise' - Property 'toPromise' does not exist on type 'Observable<Response>' 属性&#39;toPromise&#39;在&#39;Observable&#39;类型上不存在<Response> - Property 'toPromise' does not exist on type 'Observable<Response> 类型“可观察”不存在属性“ toPromise” <Response> &#39;并且参数&#39;response&#39;隐式具有&#39;any&#39;类型 - Property 'toPromise' does not exist on type 'Observable<Response>' And Parameter 'response' implicity has an 'any' type 为什么会出现错误“ Observable”类型不存在“属性“地图””的错误 <Response> &#39;”? - Why do I get the error “Property 'map' does not exist on type 'Observable<Response>'”? 角度2:类型“可观察”不存在属性“地图” <Response> &#39; - Angular 2: Property 'map' does not exist on type 'Observable<Response>' Angular10:“Observable”类型上不存在“地图”属性<Response> &#39; - Angular10 : Property 'map' does not exist on type 'Observable<Response>' Angular 6:“Observable”类型上不存在“catch”属性<Response> &#39;? - Angular 6: Property 'catch' does not exist on type 'Observable<Response>'? Angular 6:“Observable”类型上不存在“map”属性<Response> &#39; - Angular 6: Property 'map' does not exist on type 'Observable<Response>' 属性“地图”在类型“可观察”上不存在 <Response> ”。 使用Promise的角度 - Property 'map' does not exist on type 'Observable<Response>'. angular for using Promise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM