2017-07-31 24 views
2

如何使用ng-repeat從數組中的對象顯示特定屬性。這些電子郵件領域是我想顯示如何使用ng-repeat從數組中的對象顯示特定屬性

JSON什麼:

[ 
    { 
     "TypeId": 3, 
     "Type": "Listings", 
     "emails": [ 
      "[email protected]", 
      "[email protected]", 
      "[email protected]" 
     ] 
    } 
] 

控制器:

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> 

回答

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> 
+0

號我想只顯示郵件。 結果如下: {「TypeId」:3,「Type」:「Listings」,「emails」:[「[email protected]」,「[email protected]」,「[email protected]」 ]} –

+0

$ scope.emailsList包含什麼? – Vivz

+0

$ scope.emailsList = {[ 「TYPEID」:3, 「類型」: 「房源」, 「電子郵件」: 「[email protected] COM」, 「someemail3 @ EXA mple.com 「, 」someemail [email protected]「 ] }] –

0

這工作

<tr ng-repeat="item in emailsList 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.emails[$index] }}</td> 
    <td>-</td> 
</tr> 
+1

是否打印所有電子郵件?如果您的$ scope.emailsList = [{「TypeId」:3,「Type」:「Listings」,「emails」:[「[email protected] com」,「someemail3 @ exa mple.com」 ,「someemail [email protected]」]}] – Vivz

+0

@Vivz是的!他們都在印刷。你的方法:https://stackoverflow.com/a/45416174/8349557也可以。 –

相關問題