0

I want to get value when I change the dropdown on ng-change. My code as follows:-

<select class="form-control" id="cobSRQ2" ng-change="cobchange()" required>
    <option>[Select One]</option>
    <option value="Primary" selected>Primary</option>
    <option value="Secondary">Secondary</option>
    <option value="Tertiary">Tertiary</option>
</select>

I want to send the value to Angular JS controller.

Please help

Ajay Narain Mathur
  • 5,326
  • 2
  • 20
  • 32
rahul aggarwal
  • 143
  • 1
  • 11

3 Answers3

2

use ng-model for pass the value :

 app.controller('controllername',function($scope){
 $scope.drpmodel=-1
 $scope.cobchange=function(){

     alert($scope.drpmodel);

  }


 });

 <select class="form-control" id="cobSRQ2" ng-model="drpmodel" ng-change="cobchange()" required>
   <option value="-1">[Select One]</option>
   <option value="Primary" selected>Primary</option>
   <option value="Secondary">Secondary</option>
   <option value="Tertiary">Tertiary</option>
</select>
1

You could add a ng-model attribute to <select> and pass it in the ng-change function like:

<select ng-model="cob" class="form-control" id="cobSRQ2" ng-change="cobchange(cob)" required>
    ...
</select>
Evans Murithi
  • 3,197
  • 1
  • 21
  • 26
0

for ng-change to work you must provide ng-model to select

<select class="form-control" id="cobSRQ2" ng-model="myModel" ng-change="cobchange()"    required>
<option>[Select One]</option>
<option value="Primary" selected>Primary</option>
<option value="Secondary">Secondary</option>
<option value="Tertiary">Tertiary</option>
</select>

inside controller

$scope.cobchange=function(){
console.log($scope.myModel);
          }
geekbro
  • 1,293
  • 12
  • 13