【发布时间】:2017-01-20 15:20:57
【问题描述】:
我喜欢使用可观察的新角度的方法。它阻止我们编写一长串.done().fail().always()。就像在 JQuery 中一样。它仅使用| async pipe 在 NG2 的引擎盖下发生。但是,在为myObservable 加载数据时可能出现异常情况的情况如何。有什么方法可以找出模板中的 observable 失败?
// sample.component.ts
class SimpleComponent{
myObservable:Observable<string>;
constructor(private _someService:SomeService){
myObservable = _someService.getSomeDataByHttp();
}
}
// simple.component.html
<div>
<div>
{{myObservable | async}}
</div>
<div (anyErrorInObservable)="myObservable"> // Some kind of construction to figure out that observable failed to load
Oops, some kind of error appeared while fetching myObservable.
</div>
</div>
我知道这可以使用.catch() 来完成。但我希望有某种更好的方法。
感谢您的提前
【问题讨论】:
标签: angular typescript rxjs angular2-template