我使用dropzone将图像从按钮点击事件上的角度4应用程序上传到webApi。 mydrpzone.processQueue()不起作用。在上传按钮单击我得到此错误this.drpzone.processQueue不是一个函数。
这是我的代码
app.component.ts
import { Component, ViewChild } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { DropzoneModule, DropzoneComponent, DropzoneDirective,
DropzoneConfigInterface } from 'ngx-dropzone-wrapper';
@Component({
selector: 'my-app',
templateUrl: `./app.component.html`,
styleUrls: ['./app.component.css']
})
export class AppComponent {
UsreName: string = "Midhun";
@ViewChild('drpzone') drpzone: DropzoneConfigInterface;
myFiles: string[] = [];
sMsg: string = '';
getFileDetails(e: any) {
//console.log (e.target.files);
for (var i = 0; i < e.target.files.length; i++) {
this.myFiles.push(e.target.files[i]);
}
}
onSending(data: any): void {
// data [ File , xhr, formData]
const file = data[0];
const formData = data[2];
formData.append('Name', "Midhun");
console.log("enetered");
}
uploadFiles() {
//this.drpzone.processQueue();
this.drpzone.processQueue();
console.log("uploading...");
}
onSendingmultiple() {
}
onError() {
}
onSuccess() {
}
//public type: string = 'component';
public type: string = 'directive';
public config: DropzoneConfigInterface = {
url: 'http://localhost:60945/api/fileupload/',
//url: 'http://localhost:60945/user/PostUserImage',
//url:'https://httpbin.org/post',
maxFiles: 5,
clickable: true,
acceptedFiles: 'image/*',
createImageThumbnails: true,
autoProcessQueue: false,
addRemoveLinks: true,
};
constructor() { }
}
app.component.html
<div class="text-center well">
<dropzone [config]="config" #drpzone
[message]="'Click or drag images here to upload'"
(error)="onError($event)"
(sending)="onSending($event)"
(sendingmultiple)="onSendingmultiple($event)"
(success)="onSuccess($event)">
</dropzone>
</div>
<br />
<button (click)="uploadFiles()">Upload</button>
如果有人知道如何解决它,请提供帮助。
答案 0 :(得分:1)
用谷歌搜索,这就是我发现的: 该指令本身不是Dropzone实例,因此对于4.x this.dropzone.dropzone.processQueue()或5.x this.dropzone.dropzone()。processQueue()。
来到这里:https://github.com/zefoy/ngx-dropzone-wrapper/issues/60
顺便说一句,我不确定,但这似乎不正确 @ViewChild('drpzone')drpzone:DropzoneConfigInterface;
不应该 @ViewChild('drpzone')drpzone:DropzoneDirective; ?