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

Multiple File Select $event Object Getting Cleared from Memory #1223

Open
krkc opened this issue Aug 16, 2022 · 1 comment
Open

Multiple File Select $event Object Getting Cleared from Memory #1223

krkc opened this issue Aug 16, 2022 · 1 comment

Comments

@krkc
Copy link

krkc commented Aug 16, 2022

File list in $event object is getting cleared from memory while still in use
onFileSelected event of the ng2FileSelect directive when the "multiple" attribute is used.

Steps to reproduce:

  1. Create html input element of type "File" and using ng2FileSelect directive along with "multiple" attribute and create handler like (onFileSelected)="selected($event)"
  2. Run application, click input box, select one or more files
  3. In the event handler, log the value of the $event argument to the console

Desired behavior:
FileList object shows (details collapsed) in console.
Expand FileList object in console, individual Files should show in console, length property should reflect number of files

Observed behavior:
FileList object shows (details collapsed) in console.
Expand FileList object in console, no Files exist in the FileList object. Length property is 0.

Why is this happening?:
On this line the html input "value" property is being cleared before the async .emit() event has finished what it needs to do which is causing the files in the FileList to get cleared from memory before the event handler code has finished using it.

Possible fix idea:
Make deep copy of "files" variable in the onChange() event and emit that instead.

@freebreix
Copy link

I also found this to be a problem. Because the input's value gets reset when 'multiple' is applied, the files emitted are getting lost and it also destroys validation for the input in my case.

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

No branches or pull requests

2 participants