0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

He doesn't have a date object, but a length-two array of strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.