PrimeNG手动调用FileUpload

Kor*_*kig 6 typescript primeng angular

我想首先选择文件,然后通过另一个按钮而不是组件自己的Upload按钮开始上传这些文件.

我怎样才能做到这一点?

我试过的示例代码:

<button pButton type="button" label="Start Upload"
        (click)="startUpload()"></button>

<p-fileUpload #fileInput name="fileIcon"
              url="rest/batch/file/multimedia/"></p-fileUpload>


@ViewChild('fileInput') fileInput:ElementRef;

constructor( private renderer: Renderer ) { }

startUpload(){

    // this.fileInput.upload(); -> doesn't compile, undefined
    // this.fileInput.nativeElement.upload(); -> this.fileInput.nativeElement is undefined

    ?????????????????
}
Run Code Online (Sandbox Code Playgroud)

yur*_*zui 16

适用于我的示例代码

import {FileUpload} from 'primeng/primeng';

@Component({
  ...
})
export class AppComponent {
    @ViewChild('fileInput') fileInput: FileUpload;

    startUpload(){
        this.fileInput.upload();
    }
}
Run Code Online (Sandbox Code Playgroud)

Plunker示例