从AngularJS ng-options中的两个字段构建选择选项

时间:2014-06-06 12:35:22

标签: angularjs

在Angular中,我希望select中显示的内容是数组中对象的两个属性的组合。例如,我在项目上有auctionName和auctionLocation,我希望显示中的文本看起来像auctionLocation-auctionName。

<select  ng-model="selectedAuction" ng-options="item.auctionLocation as item.auctionLocation for item in auctions">
              <option value="" disabled selected>All Auctions</option>
  </select>

1 个答案:

答案 0 :(得分:1)

值可以在ng-options内连接。

对于您的情况,您可以使用:

ng-options="item.auctionLocation as item.auctionName+'-'+item.auctionLocation for item in auctions"

演示: http://plnkr.co/edit/uqoe0Hx4f0mOlU1f1wRE?p=preview