简体   繁体   中英

trigger the function on select option click

I want to trigger the function from select box.I have two option week1 and week2.If I change the select option week1 it will trigger the function.again If I click the same week1 option I want to call the same function.

JSFiddle demo

<div ng-controller="MyCtrl">
 <select ng-model="select_value" ng-change="change()">
  <option value ="1" ng-click="change()">Week 1</option>
  <option value ="2">Week 2</option>
 </select>
  <div>counter = {{counter}}</div>
   </div>



 var myApp = angular.module('myApp',[]);
 function MyCtrl($scope) {
  $scope.counter = 1;
  $scope.change = function () {
   alert('change');
  };
 }

As ng-change is triggered only when the value is changed , it is not fired when you click 2 times the same value in your <select> .

You can use ng-click instead:

<option ng-click="change()" value="1">Week 1</option>

Forked your Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM