angular-file
angular-file copied to clipboard
Request: emit newly added files separately
Looking at: https://github.com/AckerApple/angular-file/blob/development/src/file-upload/ngf.directive.ts#L169
It seems like files
contains the newly added files. Can we emit files
as an event here so that we can take action on the newly added files? I couldn't find any such event in the documentation or in my brief scan of the source code.
(filesChange)
https://github.com/AckerApple/angular-file/blob/development/src/file-upload/ngf.directive.ts#L174
Doesn't filesChange
emit all the existing files, the new and the old, since files
is already pushed into this.files
at that point?
I was thinking something like this:
que( files:File[] ){
this.files = this.files || []
// ADDED HERE, since `files` contains the files that were just selected
this.newFiles.emit(files);
Array.prototype.push.apply(this.files, files) // now, `this.files` contains the the old and the new files
this.filesChange.emit( this.files ) // when I receive `filesChange` at this point, I can't tell which ones were just added and which ones were old
...
}
Perhaps. You will need to issue a pull request for this if you wanted it.
I'm sure you could easily enough control knowing new files from existing on your own code. You could save the array of files to a different scope and just clear the files array every time files are selected
Yeah, that's what I'm doing at the moment, though it seems to make more sense to emit the diff from this directive. I'll see if I'll get a chance to issue a pull request later this week.
@rhuang if this is still an issue for you, I recently came up with a rather simple workaround for this. If you don't specify [(files)]="..." in your ngf directive, but do specify (filesChange)="someMethod($event)" the $event sends an array with just one file (the one you just added), then you can use someMethod() to perform any operations on that file you need, then you can push that file to your "files" array manually if you need to.