AngularJs get dropdown selected value


AngularJs get dropdown selected value : It is very simple to get the selected value from dropdown list. Here in this tutorial we are going to explain how you can get the selected value of dropdown list. You can use our online editor to see the output of the example.


AngularJs get dropdown selected value Example

AngularJs get dropdown selected value Example:


<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.selectedVal = '';
$scope.getSelectedValue = function(selectedOpt) {
    $scope.selectedVal = selectedOpt;
};
});
</script> 
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController">  
<select ng-model="selectedOpt" ng-change="getSelectedValue(selectedOpt)">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</select>
<p>Selected Value = {{selectedVal}}</p>  
</div>  
</div> 

</body>  
</html>      

Try it »

If you run the above example it will produce output something like this –

AngularJs get dropdown selected value Example


Advertisements

Add Comment

📖 Read More