Đây là mẫu của tôi:Cách tạo đầu vào tệp tùy chỉnh trong Ionic 2+ bằng cách tạo kiểu nút?
<label>{{label}}</label>
<input type="file" (change)="fileUpload($event)" id="file-input" style="position:absolute; top: -999999px" #fileInp>
<button ion-button (click)="onClick()">Upload</button>
và file ts:
@ViewChild('fileInp') fileInput: ElementRef;
@Input() label: string;
@Output() data = new EventEmitter<FormData>();
fileUpload(event) {
let fd = new FormData();
fd.append('file', event.srcElement.files[0]);
this.data.emit(fd);
}
onClick() {
this.fileInput.nativeElement.click();
}
Tất cả mọi thứ hoạt động tốt trên Android và trong trình duyệt, nhưng không phải trên iOS. Mã giống nhau hoạt động nếu tôi vô hiệu hóa nút trong mẫu.