ajax - Angular2 routing, how to avoid errors while data is loading -


i have route:

@routeconfig ([     {path: '/dn/', name: 'details', component: detailscomponent} ]) 

detailscomponent loads data in ngoninit method.

data shown in components template constructs like

{{data.prop1.prop2}} 

but long data not loaded, errors because data.prop1.prop2 not yet exist.

what preferred way in angular2 solve problem? with

<span *ngif="data">{{data.prop1.prop2}}</span> 

or asyncroute, or setting template dynamically?

you can use elvis operator

{{data?.prop1?.prop2}} 

this way angular doesn't try evaluate prop1 until data has value != null.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -