如何限制 Angular 中的最大上传
How to limit the maximum uploads in Angular
在angular
中如何限制单个输入文件最多上传5个
<input type="file" class="form-control" id="inputGroupFile"
onChange="uploadMultipleFiles($event)" >
app.component.ts:
uploadMultipleFiles(files) {
if (files.length > 3) {
this.alertService.error("length exceeded; files have been truncated");
let list = new DataTransfer;
for (let i = 0; i < 3; i++)
list.items.add(files[i]);
}
}
谢谢
像下面的代码,可以防止文件上传限制
filesData(files, event): void {
if (event.target.files.length > 5) {
alert("Only 5 files allow");
event.preventDefault();
event.value = ""; // clear the older value
} else {
//Put your Business logic here
}
}
此外,将 $event 作为参数传递给调用 onChange 方法的函数。
<input type="file" multiple #file (change)="filesData($event)" />
在angular
中如何限制单个输入文件最多上传5个<input type="file" class="form-control" id="inputGroupFile"
onChange="uploadMultipleFiles($event)" >
app.component.ts:
uploadMultipleFiles(files) {
if (files.length > 3) {
this.alertService.error("length exceeded; files have been truncated");
let list = new DataTransfer;
for (let i = 0; i < 3; i++)
list.items.add(files[i]);
}
}
谢谢
像下面的代码,可以防止文件上传限制
filesData(files, event): void {
if (event.target.files.length > 5) {
alert("Only 5 files allow");
event.preventDefault();
event.value = ""; // clear the older value
} else {
//Put your Business logic here
}
}
此外,将 $event 作为参数传递给调用 onChange 方法的函数。
<input type="file" multiple #file (change)="filesData($event)" />