Gloria Gloria - 10 days ago 5
Javascript Question

Angular ng-change or ng-click for select can't work

It's a sample about ng-change with checkbox.

plunker

I'd like to make the checkbox into a selection but failed.
Here's the code:

<select>
<option ng-model="confirmed" ng-change="change()">1</option>
<option ng-model="confirmed" ng-click="change()">2</option>
</select>


If somebody could help I'll be appreciate.

Answer

I did it like this:

controller:

$scope.selectChange = function() {
    switch($scope.confirmed) {
      case '1': $scope.selected = '1';break;

      case '2': $scope.selected = '2';break;
    }
  }

html:

<select ng-model="confirmed" ng-change="selectChange()">
<option>1</option>
<option>2</option>
</select>

<p>{{selected}}</p>

plnkr: http://plnkr.co/edit/N85UYTeHwRInfp60ZLsJ?p=preview

Comments