简体   繁体   English

在选择选项点击时触发功能

[英]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. 我想从选择框触发功能,我有两个选项week1和week2。如果更改选择选项week1,它将触发该功能。再次,如果我单击相同的week1选项,我想调用相同的功能。

JSFiddle demo JSFiddle演示

<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> . 由于ng-change在更改值时才触发,因此当您单击<select>相同值的2倍时不会触发。

You can use ng-click instead: 您可以改用ng-click

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

Forked your Fiddle 分叉你的小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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