[英]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.