角度2文件上传

时间:2017-04-01 22:51:40

标签: angularjs typescript file-upload

我是新的角度2,我正在尝试使用ng2-file-uploader上传文件, 但是当我尝试使用this example

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

1 个答案:

答案 0 :(得分:0)

更改:

providers: [UPLOAD_DIRECTIVES]