Getting Select box value in Angular - without using ng-options?

1.6k views Asked by At

I'm trying to modify a form which is using a select box that is populate NOT using ng-options.

The form itself is bound to an angular controller. Is there still a way for me to know the selected value of the select box even though the select values were not build using ng-options?

I have the following

<select ng-model="country" ng-change="checkValue()" 

but the checkValue function isn't even firing, apparently.

Any thoughts?

2

There are 2 answers

3
ryandrewjohnson On BEST ANSWER

You don't need to use ng-options to get the selected value. As long as your select element uses ng-model the value will be stored there.

For example:

<select ng-model="mySelectValue">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
  <option value="4">Option 4</option>
</select>

Now in your controller you would be able to access the value of the select using $scope.mySelectValue.

1
Niclas On

You should always '.' your scope variables.

$scope.address =  {};

Then bind to

ng-model="address.country"