我正在从Angular js迁移到Angular 8。如何将这些代码行迁移到Angular 8:
<button class="other-button contactUsSpecific"
type="button" data-ngf-
select="contactCtrl.uploadFiles($file)"
data-ngf-max-size="9MB"
data-ngf-model-invalid="errorFiles">
<span [innerHTML]="tk.contactus.upload"></span>
</button>
我在网上找不到Angular 8对应的data-ngf
。
发布于 2020-06-05 03:50:37
你应该已经看过答案:1来获取关于如何使用Angular 8上传文件的信息。我们可以通过在文件输入字段修改更改时的函数调用来添加文件约束的最大大小。
例如: app.component.ts
export class AppComponent {
files: FileList;
fileToUpload: File = null;
maxFileSizeBytes: number = 9e+6;
handleFileInput(event){
this.files = event.target.files;
this.fileToUpload = this.files[0];
if(this.fileToUpload.size < this.maxFileSizeBytes){
console.log("Less than required size, file will be uploaded.");
}else{
console.log("Exceeding Size");
}
}
app.component.html
<div class="form-group">
<label for="file">Choose File</label>
<input id="file" (change)="handleFileInput($event)" type="file">
</div>
在if else块中进行服务调用。附加stackblitz以获得更清晰的Angular File Upload Demo
https://stackoverflow.com/questions/61248621
复制相似问题