Toufic Batache Toufic Batache - 1 month ago 11
AngularJS Question

Get data from md-select

I am using Angular Material to make my new web app, I want to get the selected value from an

<md-select>
and the problem is that I am new to angularjs and how it works. If anyone could help me, it would be really appreciated.

HTML :

<md-input-container>
<label>Rating</label>
<md-select ng-model="userRating">
<md-option><em>None</em>
</md-option>
<md-option ng-repeat="rate in ratings" ng-value="rate.abbrev">
{{rate.abbrev}}
</md-option>
</md-select>
</md-input-container>

Answer

You can just get the value by using the $scope variable

In controller

console.log($scope.userRating);

Inorder to get the selected value on change , you can pass the selected to a function and display,

<md-select ng-change="Print()" class="inline-flex md-select-down" placeholder="Select" ng-model="model">
      <md-option ng-repeat="item in ratings" value="{{item.value}}">
        {{item.abbrev}}
      </md-option>
 </md-select>

Controller:

$scope.Print = function(){
        alert($scope.model);
}

DEMO

Comments