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
Post a Comment