doreentseng
doreentseng

Reputation: 73

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.

Upvotes: 1

Views: 7635

Answers (4)

Aniket B
Aniket B

Reputation: 488

I did like this

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

Upvotes: 0

Mountain Nguyen
Mountain Nguyen

Reputation: 1

You should put ng-click in select not in option

 <div class="input-group">
      <select class="form-control" placeholder="Type template" ng-model="eventID" ng-click="viewRuleByEvent(eventID)">
         <option value="" selected>Select Event</option>
         <option selected value="all">All Event</option>
         <option ng-repeat="event in events" value="{{event.id}}">{{event.name}}</option>
      </select>
 </div>

Upvotes: 0

tpie
tpie

Reputation: 6221

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

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388416

You need to bind them to the select element not option

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

Upvotes: 3

Related Questions