0

I have trouble to get the selected option value.

View

<select class="form-control" ng-model="mySel">
    <option ng-repeat="option in Array" value="@{{ option.id }}">@{{ option.name }}</option>
</select>

<button type="button" class="btn btn-primary" ng-click="getData(mySel);">Select</button>

Controller

scope.getData = function(selectedValue) {
    alert(selectedValue);
}

This returns undefined.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39

1 Answers1

0

No need to pass selectedValue from html use ng-model instead

<button type="button" class="btn btn-primary" ng-click="getData();">Select</button>

   $scope.getData = function() {
    console.log($scope.mySel);
   }

Working fiddle

jitender
  • 10,238
  • 1
  • 18
  • 44