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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -