I have been trying to search for image upload in angularjs2 but i didnt find any that works.Can someone please suggest me help.
我一直在尝试在angularjs2中搜索图片上传,但我找不到任何有用的工作。有人请建议我帮忙。
答案 0 :(得分:2)
您可以使用ng2-file-upload:
import {Component} from '@angular/core';
import {FileUploader} from 'ng2-file-upload/ng2-file-upload';
@Component({
selector: 'simple-demo',
template: <div>your template </div>,
})
export class SimpleDemoComponent {
public uploader:FileUploader = new FileUploader({url: URL});
public hasBaseDropZoneOver:boolean = false;
public hasAnotherDropZoneOver:boolean = false;
public fileOverBase(e:any):void {
this.hasBaseDropZoneOver = e;
}
public fileOverAnother(e:any):void {
this.hasAnotherDropZoneOver = e;
}
}
这是angular2-RC5的代码示例(截止日期为当前版本)。我强烈建议你升级到这个版本。不要忘记将指令添加到app.module.ts:
declarations: [
...
FILE_UPLOAD_DIRECTIVES,
...
],