Q:

How to get the selected value in Select element in my case?

I am trying to get the option value when user selects a option in Angular way. I have something like'
<div ng-controller="test">
  <select ng-model="selectedProduct" ng-options="product.name for product in products">
     <option value="">Please select a product</option>
  </select>
</div>

In my js
app.controller('test', function ($scope, $http, $modal) {

    console($scope.selectedProduct)   -> undefined. 

})

I want to get the selected value when user makes a selection. Can anyone help me about it? thanks a lot!

A:

You can use ngChange to fire an event whenever the value changes in the view:
<select ng-model="selectedProduct" ng-options="product.name for product in products"
        ng-change="doSomething(selectedProduct)">
    <option value="">Please select a product</option>
</select>

app.controller('test', function ($scope, $http, $modal) {
    ...
    $scope.doSomething = function (product) {
        // Do stuff with product
    };

See, also, this short demo.

