2017-05-24 16 views
1

ファイルを最初に選択し、コンポーネントの独自のUploadボタンの代わりに別のボタンでファイルをアップロードしたいとします。PrimeNGがFileUploadを手動で呼び出す

どうすればいいですか?私が試したものを

例コード:ElementRef`へ:

<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 

    ????????????????? 
} 

答えて

7

コード例働く私

import {FileUpload} from 'primeng/primeng'; 

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

    startUpload(){ 
     this.fileInput.upload(); 
    } 
} 

Plunker Example

+0

そう単純で、 '変更FileInputクラスについて'fileInput:FileUpload'はこの問題を解決しました。ありがとう.. –

+0

よろしくお願いします! – yurzui

関連する問題