Nauman Moazzam
Nauman Moazzam

Reputation: 158

Ng-Click in Select drop down options

Is that possible to use ng-click in select options? I have read other threads and everyone asked or suggested with a same controller functions. I want to trigger different functions on different select options. OR alternatively can i use button in select options?

<select>
  <option ng-click="NextWeek()" value="">Select Branches</option>
  <option ng-click="next15Days()">Select Branches</option>
</select>

Upvotes: 1

Views: 3261

Answers (1)

Santosh
Santosh

Reputation: 2333

The following should work for you using ng-model and ng-change. Below is your html code. updateSelected method will be called whenever the select option is changed.

<select ng-model="selectedOption" ng-change="updateSelected()">
  <option value="nextweek">Select Branches</option>
  <option value="next15days">Select Branches</option>
</select>

This is you controller code. The scope variable selectedOption contains the value of the selected dropdown option.

angular.module('test', [])
.controller('selectCtrl', function($scope){
  $scope.updateSelected = function(){
    switch($scope.selectedOption){
      case "nextweek":
        $scope.NextWeek();
        break;
      case "next15days":
        $scope.next15Days();
        break;
    }
  }
});

Upvotes: 2

Related Questions