rtacconi
rtacconi

Reputation: 14779

Load array of array in ng-option

I have the following array in Javascript:

[["30-11-2013", "November 2013"], ["01-11-2013", "November 2013"], ["30-11-2012", "November 2012"]]

It should populate an ng-option:

"ng-options" => "o as o for o in options", "value" => "o"

That produces this option:

<option value="1">01-11-2013,November 2013</option>

But I need

<option value="01-11-2013">November 2013</option>

Upvotes: 0

Views: 128

Answers (2)

Arham Ali Qureshi
Arham Ali Qureshi

Reputation: 1

You have to use angular filters

"o as o for o in options | date:'MMMM yyyy"

more details can be found here

http://docs.angularjs.org/api/ng.filter:date

Upvotes: 0

Brian Genisio
Brian Genisio

Reputation: 48147

Just index it:

<select ng-model="selectedModel" ng-options="o[0] as o[1] for o in options"></select>

Note that the select will be written with values of 0, 1, 2, 3, etc. This is OK, because Angular will put the correct value in ng-model when it is selected (you can't put an object in a value location, so it maps it for you).

Also, you probably (usually) don't want to set value. Just use ng-model instead.

Upvotes: 1

Related Questions