Skip to content
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

ngModelChange is being triggered on initial load #457

Open
gldmtr opened this issue Feb 7, 2022 · 8 comments
Open

ngModelChange is being triggered on initial load #457

gldmtr opened this issue Feb 7, 2022 · 8 comments

Comments

@gldmtr
Copy link

gldmtr commented Feb 7, 2022

Hi. First of all - thank you for the library.

After update from version 10 to 12 I noticed that ngModelChange is triggered right after the ui-switch component appears on a page.
It seems to be related to the commit 1382bb1
Could you please explain what was the fix about? Is it supposed to convert incoming non-boolean value into a boolean?

The issue example: https://stackblitz.com/edit/ngx-ui-switch-kz2sgk
alert is called right after the page init.

@cmckni3
Copy link
Collaborator

cmckni3 commented Feb 7, 2022

I don’t remember exactly. It might have been to set the initial value from ngModel on component init.

@gldmtr
Copy link
Author

gldmtr commented Feb 8, 2022

That probably makes sense to set an initial value but it causes some issues with side-effects being called even if a value haven't been changed.

@zac-farrugia
Copy link

Also experiencing the same problem.

@zac-farrugia
Copy link

I'm using this component to invoke an API based on the change event. As of v10.0.1, it is triggering the change event on initialization, resulting in the API being called.

For Example, I have a settings page where toggling the ui-switch will immediately call the API to disable functionality. If I use versions 10.0.1 or greater, then every time I open my settings page, it's toggling the change event.

@dgwaldo
Copy link

dgwaldo commented Jun 14, 2023

Any update on this? If you are calling an API on this load event, it can cause pretty wild issues. Any work arounds anyone has come up with?

@cmckni3
Copy link
Collaborator

cmckni3 commented Jun 30, 2023

Any update on this? If you are calling an API on this load event, it can cause pretty wild issues. Any work arounds anyone has come up with?

Not sure. I might revert the change in the commit mentioned in the first comment.

@spborhade21
Copy link

Hi @cmckni3, Are you planning to revert the changes becuase of which this intial load issue is appearing? I have used this package in my project and recently updated the version as well. Now I have to handle this inital load by adding some extra code. Let us know.

@blazekv
Copy link
Contributor

blazekv commented Jan 15, 2024

@cmckni3 I would suggest to revert that commit. Because there is another issue with this line of code. See #493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants