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

Break OnDestroy at setOnModelChange #195

Open
mqi-diamonddiagnostics-com opened this issue Jun 11, 2024 · 0 comments · May be fixed by #197
Open

Break OnDestroy at setOnModelChange #195

mqi-diamonddiagnostics-com opened this issue Jun 11, 2024 · 0 comments · May be fixed by #197

Comments

@mqi-diamonddiagnostics-com

Hi I believe this is rarely witnessed but it is better to be logically fixed.
Here is the scenario:
A component with currencyMask on a form control is defined and is being rendered. Before the GUI finished rendering, immediately, you destroy this component, by router change for example. An TypeError for reading 'setOnModelChange' will be thrown.
This is because Angular clean up control before destroying the component and any controls with valueAccessor will call registerOnChange and registerOnTouch during this cleanup procedure.
In our registerOnChange and registerOnTouch function, we call setOnModelChange directly from the handler, which is created in ngOnInit. So in the scenario above, the handler was not created yet and the registerOnChange is called.
I suggest to use this._handler?.setOnModelChange instead, so it is safer.
ngx-currency.directive.ts

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