servergrove / NgSwitchery

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

Initialize switchery with ng-model value #35

Closed FSDevelop closed 7 years ago

FSDevelop commented 8 years ago

Maybe we could declare a variable:

var pos = ngModel.$viewValue || false; switchery.setPosition(pos);

So in case there is no ng-model value, we set it to false by default. Or:

switchery.setPosition(ngModel.$viewValue || false);

trevorfrese commented 7 years ago

@aramonc can you merge this in?

trevorfrese commented 7 years ago

Now that it is in, I'm actually experiencing a worse issue, where clicking the switch toggles it between "true, false, false" instead of "true, false".

Perhaps @aramonc 's code was correct the first time with just false instead of ngModel.$viewValue

aramonc commented 7 years ago

Honestly, I don't remember why we did it this way initially. Kind of why I didn't want to add a v1 branch until we had some testing :smile:

trevorfrese commented 7 years ago

Haha well I just did the testing, and verified that @FSDevelop 's code does not work unfortunately. I would rollback the change. I was experiencing the same issue that @FSDevelop was having where the switch was not initializing with my ng-model value. After re-installing ng-switchery and updating switchery, it somehow solved the issue and now is initializing the switches with the correct ng-model values

FSDevelop commented 7 years ago

Well, it was an 'open issue' when I initially did it. It was fixing the issue, but maybe it's currently fixed by another commit.