cgarvis / angular-toggle-switch

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

Add beforeToggle callback ? #75

Open xhuberdeau opened 9 years ago

xhuberdeau commented 9 years ago

Hi, Would it be possible to add a callback before the switch is toggled ? Currently, I load data via Ajax from a DB. There is an boolean attribute for each line of this data, which is the model for each toggle switch. My use case is : When you click on the toggle, it updates the attribute in DB. My problem is that the toggle is switched before the ajax request is done. In case of a servor error, the toggle is switched let's say to "yes", the ajax return an error, the toggle is switched back to "no".

I'd like to wait for the ajax response before any switch happens. How would you do that ? Watching my data is not useful there.

Thanks.