1
votes

I am using plain options for select tag as i have to display few options only when they satisfy a condition. I need the value of the selected dropdown in controller to perform other opeartions, but the problem is i dont get the value in scope.`

<select id="selectView" ng-model="selectedView" ng-init="selectedView='plain'" ng-change=resultViewChanged()>
  <option value="plain" >Plain</option>
  <option value="grid" ng-if="user.gridView" >Grid</option>
  <option value="box" ng-if="user.boxView">Box</option>
</select>`

For now, in the controller i am just trying to get the value of selectedView. I am changing dropdown to grid and I tried below two alert's and both does not give the value grid in the alert box. How to get the value of the selected option in controller?

$scope.resultViewChanged = function() {
        alert($scope.selectedView.value); //Tried this undefined
        alert($scope.selectedView);

}

Appreciate your help

2

2 Answers

1
votes

The selected value should be store in the $scope.selectedView (without the .value after) variable as it is defined in the ng-model.

So , this:

alert($scope.selectedView);

should alert the selected value in the dropdown.

0
votes

how 'bout this?

alert(document.getElementById('selectView').value);