xpepermint / angular-ui-switch

On/off switch button for AngularJS. DEPRECATED!
278 stars 125 forks source link

ng-change should not run when the switch is disabled #50

Closed lihsai0 closed 3 years ago

lihsai0 commented 8 years ago

When I click the switch which is disabled, the on-change function switchTimesPlus is run. This should not happen!

html

<switch name="status" ng-change="switchTimesPlus(1)" ng-model="switchStatus" disabled="disabledStatus"></switch>
<button type="button" ng-click="disabledStatus = !disabledStatus">DisabledToggle</button>
<button type="button" ng-click="switchStatus = !switchStatus">StatusToggle</button>
<div>Status:{{switchStatus}}</div>
<div>Disabled:{{disabledStatus}}</div>
<div>SwitchTimes:{{switchTimes}}</div>

controller

$scope.switchStatus = false;
$scope.disabledStatus = false;
$scope.switchTimes = 0;
$scope.switchTimesPlus = function (i) {
    $scope.switchTimes += i;
};