如何使用ng-repeat从数组中的对象显示特定属性

时间:2017-07-31 12:35:28

标签: javascript angularjs

如何使用ng-repeat从数组中的对象显示特定属性。电子邮件字段是我想要显示的内容

JSON:

[
    {
        "TypeId": 3,
        "Type": "Listings",
        "emails": [
            "someemail2@example.com", 
            "someemail3@example.com", 
            "someemail5@example.com"
        ]
    }
]

控制器:

myService.getEmails().then(function (emails) {
    if (emails && emails.length) {
        $scope.emailsList = emails
    }
})

HTML:

<tr ng-repeat="item in emailsList['emails'] track by $index">
    <td>
        <div class="rounded-checkbox">
            <input class="form-check-input" type="checkbox">
            <span></span>
        </div>
    </td>
    <td class="col-xs-12">{{ item }}</td>
    <td>-</td>
</tr>

2 个答案:

答案 0 :(得分:0)

假设$scope.emailsList是电子邮件数组,请更改您的HTML

<tr ng-repeat="item in emailsList[0].emails track by $index">
    <td>
        <div class="rounded-checkbox">
            <input class="form-check-input" type="checkbox">
            <span></span>
        </div>
    </td>
    <td class="col-xs-12">{{ item }}</td>
    <td>-</td>
</tr>

答案 1 :(得分:0)

此作品

An error occurred while loading ./spec/lib/zombie_spec.rb.
Failure/Error: require 'test'

LoadError:
  cannot load such file -- test
# ./spec/lib/zombie_spec.rb:2:in `require'
# ./spec/lib/zombie_spec.rb:2:in `<top (required)>'
No examples found.


Finished in 0.00026 seconds (files took 0.40148 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples