Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<select> showing more than one field using ng-options query

Currently, I have an angular.js <select> filled by the following query:

c.ip for c in cameras track by c.idCamera

and it produces on my <select> something like:

<option value="1">192.168.0.121</option>
<option value="2">192.168.0.122</option>
<option value="3">192.168.0.123</option>
... 

my $scope has a list of cameras and I can see the IP, but I want to use two fields as label -- let's say camera's IP and type.

I'm looking way to produce as output something like this:

<option value="1">192.168.0.121 - ZOOM</option>
<option value="2">192.168.0.122 - PAN </option>
<option value="3">192.168.0.123 - ZOOM</option>
... 

I'm currently using angular.js beta 6, if that has any additional bearing on the matter.

like image 907
Sombriks Avatar asked Jan 29 '26 18:01

Sombriks


1 Answers

The label in the ngOptions directive is an expression like all the others. It can be as complex as you want:

<select ng-model="myCamera" ng-options="(c.ip + ' - ' + c.type) for c in cameras track by c.idCamera"></select>
like image 136
Blackhole Avatar answered Jan 31 '26 07:01

Blackhole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!