-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch-change="onChange()" gets called immediately when loading #120
Comments
I tried to debug this and noticed that the switchChange() is being called upon a model change. I'm wondering why this would need to call the switchChange function if a model is changed ?
|
What do you mean? |
ok I'll try that, what's switch-change for ? |
It's for model changes. |
The problem is most likely that the ng-model value is evaluated as undefined when the template is rendered and when the controller sets available to false the directive interprets it as a model change, which it strictly speaking is even though one might argue that a ng-model change from undefined->true/false should not trigger a model change since it's almost always just an init case. The problem can be solved by adding an ng if like this
to the bs-switch input or a wrapping element, ng-show will not work since that wont stop the template from rendering the input element. |
I also ran into this and I find it unexpected behaviour. In my app an undefined settings item gets initialized and this is triggering switch-change. Using ng-change now. It works as I wanted it to work. |
Please re-open if you still have this issue. |
Hi, I was looking to wire up this directive to call a web service api whenever there was a change in the value. I saw that there is a function that I can place on the switch-change attribute, however, I noticed that this is getting called on first render (when the page loads) as opposed to when the user has interacted with the switch.
I tested this using :
//model:
//onChange Function
My element :
The text was updated successfully, but these errors were encountered: