Angularjs Getting The Value Of A Selected Dropdown Option In A Variable November 25, 2023 Post a Comment I have dropdown selection menu & want to send the dropdown selected value in request params of api. My code is... Solution 1: Bind a model in your select dropdown. Like below <selectclass="form-control" id = "SelectionInput_reason" data-ng-model="inputReason"> CopyIn your controller you will get selected option console.log($scope.inputReason)Solution 2: Here is a sample code with a fiddle attached var myApp = angular.module('myApp', []); myApp.controller('MyCtrl', function($scope) { $scope.shelf = [{ 'name': 'Banana', 'value': '$2' }, { 'name': 'Apple', 'value': '$8' }, { 'name': 'Pineapple', 'value': '$5' }, { 'name': 'Blueberry', 'value': '$3' }]; $scope.cart = { 'fruit': $scope.shelf[0] }; });Copy<divng-controller="MyCtrl"><div> Fruit List: <selectng-model="cart.fruit"ng-options="state as state.name for state in shelf"></select><br/><tt>Cost & Fruit selected: {{cart.fruit}}</tt></div></div>CopyFiddle link : http://jsfiddle.net/Td2NZ/1867/My advise in this scenario is try to keep all input choices as a Js Object (Like $scope.shelf in this code) cause thats what Angular is built for rigid and robust handling of the data, eventually you could just load those options from a server or json file and not having to touch your HTML at all!Hope this helps! Share Post a Comment for "Angularjs Getting The Value Of A Selected Dropdown Option In A Variable"
Post a Comment for "Angularjs Getting The Value Of A Selected Dropdown Option In A Variable"