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" } ] } ] }
它看起来像你想要的
<li *ngFor="let item of menuItems.children"> {{item}} </li>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。