ngx-ui-switch icon indicating copy to clipboard operation
ngx-ui-switch copied to clipboard

ngModelChange is being triggered on initial load

Open gldmtr opened this issue 3 years ago • 8 comments

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 https://github.com/webcat12345/ngx-ui-switch/commit/1382bb140422c5efca4df9d6e15030da3535c2e2 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.

gldmtr avatar Feb 07 '22 12:02 gldmtr

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

cmckni3 avatar Feb 07 '22 17:02 cmckni3

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.

gldmtr avatar Feb 08 '22 07:02 gldmtr

Also experiencing the same problem.

zac-farrugia avatar May 31 '22 10:05 zac-farrugia

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.

zac-farrugia avatar Jul 13 '22 01:07 zac-farrugia

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?

dgwaldo avatar Jun 14 '23 00:06 dgwaldo

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.

cmckni3 avatar Jun 30 '23 00:06 cmckni3

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.

spborhade21 avatar Sep 01 '23 20:09 spborhade21

@cmckni3 I would suggest to revert that commit. Because there is another issue with this line of code. See https://github.com/webcat12345/ngx-ui-switch/issues/493

blazekv avatar Jan 15 '24 13:01 blazekv