AngularJS - 如何引用NG-重复内的属性名 [英] AngularJS - How can I reference the property name within an ng-Repeat

查看:100
本文介绍了AngularJS - 如何引用NG-重复内的属性名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了呈现在一个对象的属性值,我也想呈现的属性名称作为标签。有没有办法用 NG-重复来做到这一点?例如:

 < UL>
    <李NG重复=数据选项> {{propertyName的}} {{}选项}< /李>
< / UL>

这可能会吐出这样的:

 < UL>
    <立GT;姓名:John< /李>
    <立GT;电话:(123)456-7890< /李>
    <立GT;国家:England< /李>
< / UL>


解决方案

试试这个:

 < UL>
    <李NG重复=(键,VAL)数据> {{键}} {{VAL}}< /李>
< / UL>

In addition to rendering the value of the properties in an object, I'd also like to render the property name as a label. Is there a way to do this with ng-repeat? For example:

<ul>
    <li ng-repeat="option in data">{{propertyName}}: {{option}}</li>
</ul>

Which might spit out something like this:

<ul>
    <li>Name: John</li>
    <li>Phone: (123) 456-7890</li>
    <li>Country: England</li>
</ul>

解决方案

Try this:

<ul>
    <li ng-repeat="(key,val) in data">{{key}}: {{val}}</li>
</ul>

这篇关于AngularJS - 如何引用NG-重复内的属性名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆