Questions tagged [ng-options]

Related with AngularJS .HTML SELECT element with angular data-binding. Optionally ngOptions attribute can be used to dynamically generate a list of

Related with AngularJS. HTML SELECT element with angular data-binding. Optionally ngOptions attribute can be used to dynamically generate a list of elements for a element using an array or an object obtained by evaluating the ngOptions expression.

More details

929 questions
455
votes
7 answers

Working with select using AngularJS's ng-options

I have read about it in other posts, but I couldn't figure it out. I have an array, $scope.items = [ {ID: '000001', Title: 'Chicago'}, {ID: '000002', Title: 'New York'}, {ID: '000003', Title: 'Washington'}, ]; I want to render it…
Andrej Kaurin
  • 11,592
  • 13
  • 46
  • 54
194
votes
5 answers

ng-options with simple array init

I'm a little bit confused with Angular and ng-options. I have a simple array and I want to init a select with it. But, I want that options value = label. script.js $scope.options = ['var1', 'var2', 'var3']; html
davioooh
  • 23,742
  • 39
  • 159
  • 250
72
votes
8 answers

How to set the value attribute for select options?

Source JSON data is: [ {"name":"Alabama","code":"AL"}, {"name":"Alaska","code":"AK"}, {"name":"American Samoa","code":"AS"}, ... ] I try ng-options="i.code as i.name for i in regions" but am getting:
65
votes
12 answers

Angularjs ng-options using number for model does not select initial value

I'm trying to use ng-options with a maybe possible to turn into something like this: . Initially, when the pages reload and no option element is selected, the HTML generated like below: . I want to use Angular's ng-options like this Controller: $scope.genders = [{code: "M",…
Rahul Prasad
  • 8,074
  • 8
  • 43
  • 49
33
votes
3 answers

Setting selected values for ng-options bound select elements

Fiddle with the relevant code: http://jsfiddle.net/gFCzV/7/ I'm trying to set the selected value of a drop down that is bound to a child collection of an object referenced in an ng-repeat. I don't know how to set the selected option since I can't…
sonicblis
  • 2,926
  • 7
  • 30
  • 48
32
votes
2 answers

AngularJS - ngOptions: How to order by Group Name and then by Label

Let's assume I have the following data array in this form: var data = [{group:GroupA, label: BB}, {group:GroupB, label: DD}.....]. My binding would be something like: