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);
}
}
我收到此错误:
属性'toPromise'在'Observable'类型上不存在
4 回答
你需要像这样添加运算符:
这是您想要使用的每个rxjs运算符所必需的 .
尝试从'@ angular / http'向您的import语句添加'Response',如下所示:
另外我注意到你没有从角度核心导入Ingectable,尽管你使用@Injectable装饰器 .
一开始就使用这个导入
import {Observable} from "rxjs/Rx";
对于其他任何偶然发现此事的人(它是我的顶级谷歌链接),请参阅下面的链接答案之一
https://github.com/Microsoft/TypeScript/issues/8518#issuecomment-229506507
正如它所说,在Visual Studio 2015中,您可以通过更新您的打字稿版本来解决此问题
https://www.microsoft.com/en-us/download/details.aspx?id=48593