cgarvis / angular-toggle-switch

AngularJS Toggle Switch
http://cgarvis.github.io/angular-toggle-switch
MIT License
160 stars 124 forks source link

don't set any values on the model #5

Closed nathantsoi closed 11 years ago

nathantsoi commented 11 years ago

readers shouldn't update data to avoid unwanted side effects

here's a concrete example where this is a problem: say we have a model: Car, that has Passengers, which get populated after someone selects a car in the UI

car.passengers should be null until the car is selected, but if a toggle-switch is created with the model set to car.passengers.some_switch, it will set car.passengers.some_switch to false. this sets car.passengers to an object of the wrong type and populates some_switch, breaking the null comparison

cgarvis commented 11 years ago

Fixed in 3f3b8fe4e079338a09f5ada15b7fce08a6d6742c. I was not able to merge your PR due to your readme changes.

nathantsoi commented 11 years ago

Whoops, thx for updating. Changed the readme after creating the PR.

Happy to revert and create a PR for the switch labels if you'd like to merge that in?

cgarvis commented 11 years ago

Why do you want to set the labels from the attrs? From everything I've read, we should be doing that using data-binding. I am having some issues with it current. Test pass but the demo doesn't set the defaults.