简体   繁体   English

primeNG p-fileUpload自定义模式回调未触发

[英]primeNG p-fileUpload Custome mode callback not triggering

primeNG p-fileUpload is not trggering uploadHandler when I enable the customeMode. 当我启用customeMode时, primeNG p-fileUpload不会在上载处理程序。 Could you please help me to fix this. 您能帮我解决这个问题吗?

I need to make server request manually. 我需要手动发出服务器请求。

   <p-fileUpload name="invoiceFiles[]" customUpload="true" [showUploadButton]="false" multiple="multiple"
                [showCancelButton]="false" (uploadHandler)="invoiceUpload($event)">
              </p-fileUpload>

If you are hiding the uploadbutton, you need another way to capture the files that are selected. 如果您隐藏了上载按钮,则需要另一种捕获所选文件的方法。 one way to do that is to use onSelect to store the files in an array that can be submitted with a form. 一种方法是使用onSelect将文件存储在可以与表单一起提交的数组中。 Here is an example: 这是一个例子:

<p-fileUpload name="demo[]" #fileInput (onSelect)="onSelect($event)" [showUploadButton]="false" customUpload="true"></p-fileUpload>

And in the controller: 并在控制器中:

import { FormArray, FormControl, FormGroup, FormBuilder, Validators} from '@angular/forms';

private myFormFilesToUpload: FormArray;

constructor(private _fb: FormBuilder) {}

this.myForm = this._fb.group({
        //...other form controls
        filesToUpload: this._fb.array([])
});

this.myFormFilesToUpload = this.myForm.get('filesToUpload') as FormArray;

onSelect(event) {
    if (event.files && event.files.length > 0) {
        this.myForm.markAsDirty();
        this.myFormFilesToUpload.push(this._fb.group({
            fieldName: 'my_images',
            files: this._fb.array(Array.from(event.files))
        }));
    }
}

Then the files should get sent went you submit the form. 然后,如果您提交表单,文件应该发送出去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM