0

I need to get a select value from a dropdown using angular.js

angular code:

var sbAdmin2 = angular.module('sbAdmin2',[]);
sbAdmin2.controller('dropdownCtrl', function($scope,$http){
    $scope.chnagecustomer= function() {
        $scope.value=$scope.dropdown;
        console.log($scope.value);
    };
});

html code:

<select 
  ng-controller="dropdownCtrl" 
  class="form-control" 
  ng-change="chnagecustomer()" 
  ng-model="selectedPerson" 
  id="p_client_main" 
  name="p_client_main" 
  tabindex="2">
    <option value=""> </option>
    <option value="a">a</option>
    <option value="b">b</option>
    <option value="c">c</option>
</select>
  • in jquery .val() would work to get dropdown value which is selected
  • but I need to know the angular way.
  • I'm new in angular. Any help is much appreciated.

4 Answers 4

2

You always got selected value in ng-model (selectedperson in your code)

var app = angular.module('myApp', []);
app.controller('myController', function ($scope) {
  $scope.change = function () {
    alert($scope.value);
  }
})

simple example: http://plnkr.co/edit/BEmcCWnmxRJvcGrM1Btp?p=preview

Sign up to request clarification or add additional context in comments.

Comments

1

It doesn't appear that you're accessing the model's value in your change function. Edit that function to look like this:

$scope.chnagecustomer= function() {
  $scope.value = $scope.selectedPerson;
  console.log($scope.value);
};

Comments

0

try using {$scope.value=$scope.selectedPerson;} as thats your model variable

Comments

0

Try $scope.value=$scope.selectedPerson the value of your dropdown list should be the model.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.