angular - angular2: The hierarchic Json data cannot displayed correctly -
i test angular2-seed (https://github.com/angular/angular2-seed) displaying repo-detail, pure json string, in table. appending following code in repo-detail.component.html:
<table> <tr> <td>{{repodetails.id}}</td> <td>{{repodetails.owner.login}}</td> <!--it's ok without line--> </tr> </table>
now data not correctly displayed. in console, got:
zone.js:388 unhandled promise rejection: error in ./repodetailcomponent class repodetailcomponent - inline template:7:12 caused by: cannot read property 'login' of undefined ; zone: angular ; task: promise.then ; value: viewwrappederror {_nativeerror: error: error in ./repodetailcomponent class repodetailcomponent - inline template:7:12 caused by: ca…, originalerror: typeerror: cannot read property 'login' of undefined @ debugappview._view_repodetailcomponent0.…, context: debugcontext} typeerror: cannot read property 'login' of undefined @ debugappview._view_repodetailcomponent0.detectchangesinternal (/appmodule/repodetailcomponent/component.ngfactory.js:108:72) @ debugappview.appview.detectchanges
...
try adding
<table> <tr *ngif="repodetails"> <td>{{repodetails.id}}</td> <td *ngif="repodetails.owner">{{repodetails.owner.login}}</td> <!--it's ok without line--> </tr> </table>
what doing here rendering template when repodetails.owner
available.
Comments
Post a Comment