2017-04-01 118 views
0

我新角2,我試圖用ng2-file-uploader上傳文件, 但是當我嘗試使用this example角2文件上傳

import {Component} from '@angular/core'; 
import {UPLOAD_DIRECTIVES} from 'ng2-file-uploader/ng2-file-uploader'; 

@Component({ 
    selector: 'demo-app', 
    templateUrl: 'app/demo.html', 
    directives: [UPLOAD_DIRECTIVES], 
}) 
export class DemoApp { 
    uploadFile: any; 
    postId: number; 
    options: Object = { 
    url: 'http://localhost:10050/upload', 
    params: { 'post_id': this.postId } 
    }; 

    handleUpload(data): void { 
    if (data && data.response) { 
     data = JSON.parse(data.response); 
     this.uploadFile = data; 
    } 
    } 
} 

我得到下指令紅線:[UPLOAD_DIRECTIVES] ,

npm install ng2-file-uploader 

所以劑量任何一個有一個想法,如何在正確的方式指示?

enter image description here

+0

http://www.angulartutorial.net/2018/01/file-upload-and-send-data-to-backend html的 – Prashobh

回答

0

更改爲:

providers: [UPLOAD_DIRECTIVES]