Questions tagged [angularjs-ng-options]

The ngOptions attribute can be used to dynamically generate a list of

From Angularjs documentation:

In many cases, ngRepeat can be used on <option> elements instead of ngOptions to achieve a similar result. However, ngOptions provides some benefits such as reducing memory and increasing speed by not creating a new scope for each repeated instance, as well as providing more flexibility in how the <select>'s model is assigned via the select as part of the comprehension expression. ngOptions should be used when the <select> model needs to be bound to a non-string value. This is because an option element can only be bound to string values at present.

When an item in the <select> menu is selected, the array element or object property represented by the selected option will be bound to the model identified by the ngModel directive.

Optionally, a single hard-coded <option> element, with the value set to an empty string, can be nested into the <select> element. This element will then represent the null or "not selected" option.

338 questions
76
votes
3 answers

Is it possible to concatenate values in Angular ng-options

Basically, I'm trying to populate a select box but concatenate values from the first_name column and last_name column. What I want to do (doesn't work): to bind a numeric integer value to a list of corresponding options. In my controller, I have something like this: myApp.controller('MyCtrl', function() { var self = this; var…
BrandonLWhite
  • 1,866
  • 1
  • 23
  • 26
30
votes
3 answers

How to filter a select with ng-options in Angular?

I've written the following proof-of-concept of an Angular app that allows a person to vote for President of the US.
Vivian River
  • 31,198
  • 62
  • 198
  • 313
21
votes
6 answers

Angularjs select does not mark matching model as selected

I have a problem with my ngModel in select not showing as selected. Both id and name are matching but its not working, see selectedState. Pointing model to the actual object within options array works, see selelectedState2. No idea whats going on…
Micor
  • 1,502
  • 4
  • 20
  • 39
15
votes
4 answers

Can't set selected value of ng-options

I am trying to populate a drop-down select options list and set a default selected value using ng-model and ng-options. I have the following code in my view: And…
Inigo
  • 8,110
  • 18
  • 62
  • 110
13
votes
1 answer

How to use an angularJs filter on items label within ng-options

Given a select list loaded with product options, I want the label to be in the format of option name and then price in parenthesis. So for example: "Product Option B ($1,432.12)". My option object has the properties "name" and "price". Price is…
Ryan Langton
  • 6,294
  • 15
  • 53
  • 103
11
votes
3 answers

How to sort array in ng-options by key?

There is such array: month: Array[13]0: "M"1: "January"2: "February"3: "March"4: "April"5: "May"6: "June"7: "July"8: "August"9: "September"10: "October"11: "November"12: "December" I do: ng-options="key as value for (key, value) in data.month |…
10
votes
3 answers

AngularJS: ng-model switching int to string

I'm currently working on an app in Angular. So far, everything has been going -quite- well. I'm really, really new to angular and am amazed that it took so long for the first real roadblock. Situation: I have an array of objects each with an…
10
votes
1 answer

Angular.js Select with ngOptions: Label the optgroup

I just started to play with Angular.js and have a question about ngOptions: Is it possible to label the optgroup? Lets assume 2 objects - cars and garages. cars = [ {"id": 1, "name": "Diablo", "color": "red", "garageId": 1}, {"id": 2,…
WebCore IT
  • 165
  • 1
  • 7
9
votes
2 answers

Angular select and ng-options

I have this angular select: Data: [ {…
8
votes
2 answers

angularjs select without ng-options or static options

How, to use a static select in angularjs. I wanna create a select ng-model with change event with statc values.
populated via ng-options. In a specific case, when two values are adjacent in the ordered model list and the values have the same first letter, the updating of the model value in angular breaks. This may be a browser event issue…
7
votes
6 answers

Angularjs Dropdown OnChange Selected Text and Value

I am new to AngularJS and trying to get Selected Text and Value from Dropdown. I followed a lot of tutorials with still unable to get there. SelectedValue and SelectedText are always undefined. Below is my code: Html:
Usman Khalid
  • 3,032
  • 9
  • 41
  • 66
6
votes
2 answers

Why the Angular ng-options value contains the value data type?

Guys after I used the angular directive ng-options I got this result