ngf-select to Angular 8



我正在从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

您应该看看答案: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>

如果else阻塞,请拨打服务呼叫。附加stackblitz以提高清晰度Angular文件上传演示

最新更新