Angular2 rc.6
在json数据上运行循环时出现以下错误
core.umd.js:5995 EXCEPTION:app / modules / mbs / components / menu.html:5:4引起的错误:无法找到’object’类型的不同支持对象'[object Object]’. NgFor仅支持绑定到诸如Arrays之类的Iterables.
我的html循环,注意:我只是想在响应中迭代属性和数组.
<li *ngFor="let item of menuItems"> {{item}} </li>
我的服务方法
getMenuItems():Promise<any>{ return this.http.get('api/menu').toPromise(). then(response => response.json()) .catch(this.handleError) }
以下是我的json回复
{ "text": "Menu","children": [ { "text": "Home","url": "/spatt-web/home" },{ "text": "Configure","children": [ { "text": "Tri-Party Program","children": [ { "text": "Margins and Filters","url": "/sp-rrp/config/operation" },{ "text": "Fields and Desirability","url": "/spatt-rrp/config/program" } ] },{ "text": "Shared Settings","url": "/shared-config/config" },{ "text": "SOMA Limits","url": "/outright-config/config" } ] },{ "text": "Plan","children": [ { "text": "Tri-Party RRP Operations","url": "/spatt-rrp/plan" } ] },{ "text": "Track" },{ "text": "Administer" },{ "text": "Help","children": [ { "text": "RRP Operations","url": "RRPference" },{ "text": "RRP Margin Calls and Recalls","url": "RRPRecallference" } ] } ] }
它看起来像你想要的
原文链接:https://www.f2er.com/angularjs/141542.html<li *ngFor="let item of menuItems.children"> {{item}} </li>