[英]Property 'toPromise' does not exist on type 'Observable<Response>'
import { Headers, Http } from '@angular/http';
@Injectable()
export class PublisherService{
private publishersUrl = 'app/publisher';
constructor(private http: Http) { }
getPublishers(): Promise<Publisher[]>{
return this.http.get(this.publishersUrl)
.toPromise()
.then(response => response.json().data)
.catch(this.handleError);
}
}
I am getting this error: 我收到此错误:
Property 'toPromise' does not exist on type 'Observable'.any 属性'toPromise'在'Observable'类型上不存在
You need to add the operator like this: 你需要像这样添加运算符:
import 'rxjs/add/operator/toPromise';
This is needed for every rxjs operator you want to use. 这是您想要使用的每个rxjs运算符所必需的。
Try adding 'Response' to your import statement from '@angular/http' like this : 尝试从'@ angular / http'向您的import语句添加'Response',如下所示:
import {Http, Headers, Response} from '@angular/http';
Also i noticed you don't import Ingectable from angular core although you use @Injectable decorator. 另外我注意到你没有从角度核心导入Ingectable,尽管你使用@Injectable装饰器。
import { Injectable } from '@angular/core';
一开始就使用这个导入
import {Observable} from "rxjs/Rx";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.