我正在使用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>
如果有人知道如何解决它,请提供帮助。
刚刚用谷歌搜索了一下,这就是我发现的:指令本身不是 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; ?