nbs*_*bsp 7 typescript angular
我的代码是
import 'rxjs/Rx';
...
let _this = this;
return new Promise(function(resolve, reject) {
_this.http[method](url, data, {
headers: headers
})
.toPromise()
.then(
(data) => {
resolve(data);
},
error => {
reject(error);
}
);
});
"订阅"不是来自我的代码,看起来像是有角度的原始东西.
错误信息:
EXCEPTION: Error: Uncaught (in promise): TypeError: _this.http.get(...).subscribe is not a function
您正在对抗Angular2从基于异步范例移植promise到替代范例的倡议reactive-extensions。不要使用 Promise,而是使用subscribe:
import 'rxjs/Rx';
...
invoke<T>(onNext: (data: T) => void, onError: (error: any) => any) {
this.http[method](url, data, {
headers: headers
})
.map(response => response.json() as T)
.subscribe(onNext, onError);
});
Run Code Online (Sandbox Code Playgroud)
我也写了一篇关于此的博客文章。
https://ievangelist.github.io/blog/angular-2-http/
| 归档时间: |
|
| 查看次数: |
4726 次 |
| 最近记录: |