xpepermint / angular-ui-switch

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

ng-change adds parenthesis #10

Open dhaub opened 9 years ago

dhaub commented 9 years ago

Remove the () that are added on ng-change in line 12. Change

  html +=   attrs.ngModel ? ' ng-click="' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';

to

  html +=   attrs.ngModel ? ' ng-click="' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '"' : '"') : '';

This causes problems when the supplied ng-change is actually a function with supplied parameters. This problem came up when using the switch inside an ng-repeat section. The function supplied to ng-change needed to have a parameter with the specific item.

<div ng-repeat="item in items">
  <switch name="isActive" ng-model="item.isActive" class="green" ng-change="activate(item);"></switch>
</div>

Awesome control. Thanks for putting it together.

Stupidism commented 8 years ago

meet this bug today