In the (onRemove) function of a p-fileUpload, is it possible to get a list of the remaining...

Discussão em 'Angular' iniciado por Tim, Dezembro 2, 2024.

  1. Tim

    Tim Guest

    I have an PrimeNG Angular app that uses a p-fileUpload with its [multiple] tag set to true.

    I want to keep a running list of the pending files in the list - both after files are added, and also whenever a file is removed from the list.

    When files are added, this is no problem.

    I just do this in the html...

    <p-fileUpload #fileUpload
    (onSelect)=onFilesSelectedToUpload($event.currentFiles)"
    [multiple]="true">


    ...and then in the typescript file I just do this:

    onFilesSelectedToUpload(files: any[]) {
    files.forEach(file => {
    //Free to do whatever I want with each added file
    }
    }


    What I would like to do, though, is the same thing on the (onRemove) event - only I can only get ahold of the file to remove.

    Would like to do something like this:

    <p-fileUpload #fileUpload
    (onSelect)=onFilesSelectedToUpload($event.currentFiles)"
    (onRemove)=onFileRemoved($event.currentFiles)"
    [multiple]="true">

    onFileRemoved(files: any[]) {
    files.forEach(file => {
    //Free to do whatever I want with the remaining files
    //I don't even care about the file that's been removed!
    }
    }


    But of course I can't because (onRemoved) is only concerned with the file that is being removed, and only lets me do something like this:

    <p-fileUpload #fileUpload
    (onSelect)=onFilesSelectedToUpload($event.currentFiles)"
    (onRemove)=onFileRemoved($event.file)"
    [multiple]="true">

    onFileRemoved(file: any) {
    //How can I get a list of the remaining files?
    }


    Any suggestions?

    Thank you!

    Continue reading...

Compartilhe esta Página