简体   繁体   中英

More element in select ng-options or an output field with detalis about ng-options selected

I have have this select field:

在此处输入图片说明

code:

<select ng-model="productForm.productDesc.idproductDesc" ng-options="opt2.idproductDesc as opt2.description for opt2 in productDesc"/>

where productDesc is a result JSON text from a query, where productDesc is the table and idproductDesc and description are two attribute of this table. I want to show another attribute of productDesc , such as prize ( opt2.price in this case). I want something like that:

在此处输入图片说明

however: opt2.name - opt2.price , for example if opt2.name is "Patatine fritte classiche" and opt2.price is 1: "Patatine fritte classiche - 1" (like in the second picture). Otherwise an output field with the opt2.price of the selected element, in this way:

在此处输入图片说明

how can I do it?

Solved in this way:

<select ng-model="productForm.productDesc.idproductDesc">
  <option ng-selected="{{productDesc.idproductDesc == productForm.productDesc.idproductDesc}}" ng-repeat="productDesc in productDescs" value="{{productDesc.idproductDesc}}">
    {{productDesc.price}} - {{productDesc.description}}
  </option>
</select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM