angular - Angular2 Observable error handling in template -


i approach of new angular observables. prevents writing long chain of .done().fail().always(). in jquery. happening under hood in ng2 using | async pipe. how case when there might exceptional case while loading data myobservable. there way how figure out observable failed in template?

// 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"> // kind of construction figure out observable failed load        oops, kind of error appeared while fetching myobservable.    </div> </div> 

i know can done using .catch(). hope there kind of better approach.

thanks advance

there no way handle errors in template. can use operators catch() ensure errors don't reach template.

see related open issue https://github.com/angular/angular/issues/7539


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -