Sombriks
Sombriks

Reputation: 3622

<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.

Upvotes: 3

Views: 1007

Answers (2)

AlexHv
AlexHv

Reputation: 1734

You can do this :

(c.ip + ' ' + c.yourField) for c in cameras track by c.idCamera

Upvotes: 1

Blackhole
Blackhole

Reputation: 20401

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>

Upvotes: 4

Related Questions