Angular + Ionic, ng-options implement value tag in

2019-09-17 19:47发布

I am using ng-options on a <select> like this ng-options="item.model for item in prodataSelect | unique:'model' "

But I would like the <value="" tag of the generated options to contain the item.id instead of the autoincremental value use by ng-options.

How to achieve this ?

HTML:

<select id = "chosenmodel" class="button button-full button-dark" ng-model="selectedModel" ng-options="item.model for item in prodataSelect | unique:'model' "> 
  <option value="">Select a Model</option>
</select>

<a id="submitbutton" class="button button-block button-dark ui-btn ui-btn-b ui-corner-all" ng-click='launchCompute()' href="#/app/compute/result">Compute my board</a>

Each item in prodataSelect is an object :

{
  brand: "John",
  fun: "0",
  id: 1
},
{
  brand: "you",
  fun: "0",
  id: 185
},
{
  brand: "Ark",
  fun: "0",
  id: 17
},

2条回答
Melony?
2楼-- · 2019-09-17 20:17

use below syntax

       `ng-options="item.id as item.model for item in prodataSelect"`

read more about it here

查看更多
Rolldiameter
3楼-- · 2019-09-17 20:35

Use "track by item.id" to set option value to id

ng-options="item.id as item.model for item in prodataSelect track by item.id"

查看更多
登录 后发表回答