servergrove / NgSwitchery

An AngularJS Directive for Switchery
MIT License
87 stars 49 forks source link

bugfix and new attributes #37

Open dejan7 opened 8 years ago

dejan7 commented 8 years ago

Two things in this pull request:

  1. I've added ui-switch-true-value and ui-switch-false-value attrs, see readme for description, i've updated it.
  2. You had
    scope.$watch(function () {
        return ngModel.$modelValue;
    }, function(newValue,oldValue) {
        initializeSwitch()
    });

in link function. And then at the bottom again you had initializeSwitch(); one more time. This caused init function to be called every time switchery is toggled from the interface. Which caused

              element.addEventListener('change',function(evt) {
                    scope.$apply(function() {
                        ngModel.$setViewValue(element.checked);
                    })

To be added every time switchery is toggled. So you'd end up calling ngModel.$setViewValue dozens of times on every change for a single instance.