MiH*_*awk 73 rxjs typescript angular2-services angular
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
属性'toPromise'在'Observable'类型上不存在
Din*_*tro 158
你需要像这样添加运算符:
import 'rxjs/add/operator/toPromise';
Run Code Online (Sandbox Code Playgroud)
这是您想要使用的每个rxjs运算符所必需的.
小智 10
尝试从'@ angular/http'向您的import语句添加'Response',如下所示:
import {Http, Headers, Response} from '@angular/http';
Run Code Online (Sandbox Code Playgroud)
另外我注意到你没有从角度核心导入Ingectable,尽管你使用@Injectable装饰器.
import { Injectable } from '@angular/core';
Run Code Online (Sandbox Code Playgroud)
一开始就使用这个导入
__CODE__
| 归档时间: |
|
| 查看次数: |
50734 次 |
| 最近记录: |