0
我有一個路線:Angular2路由,如何避免錯誤,同時數據加載
@RouteConfig ([
{path: '/dn/', name: 'Details', component: DetailsComponent}
])
DetailsComponent在ngOnInit方法加載數據。
數據顯示在組件模板與結構,如
{{data.prop1.prop2}}
但只要沒有加載數據,因爲data.prop1.prop2還不存在我得到的錯誤。
angular2中解決此問題的首選方法是什麼?用
<span *ngIf="data">{{data.prop1.prop2}}</span>
還是用AsyncRoute或者動態設置模板?
最簡單的方法是使用' {{data.prop1.prop2}}'對象和'' 。 – xphong