Reputation: 4642
To begin with, I am an absolute beginner in front-end development, thus please excuse me if the question is too elementary.
The project I am working on, a drop-down list has been defined as:
<div ng-controller="FacetController">
<div class="spnlocationdrop-container" ng-hide="isservicelocal">
<select class="spnlocationdrop" ng-model="$parent.locationsearch" ng-options="location for location in locations | sortArray ">
<option value="">All Cities</option>
</select>
</div>
</div>
The list contains cities, out-of which the user has to select one. The value has to be stored, and sent to the backend via an AJAX call.
How do I get the selected value? Until now, I've been doing that using the document.getElementByID().value()
function, but since the above list contains no ID
, how do I get the value?
Upvotes: 0
Views: 33
Reputation: 6527
ng-model
will have the value of the option selected.
Here's a simple working example: Plunker
In my example, data.singleSelect
has the value you need so I'm able to output that to the view using {{ data.singleSelect }}
though if I wanted to access it in my controller I would do var input = $scope.data.singleSelect
and then pass that input
variable to the backend via an AJAX call.
Upvotes: 1