Reputation: 1271
I have a div
and ion-input #fileInput type="file" accept="image/*" id="fileInput" [(ngModel)]="imageFilePath" (ionChange)="imageFilePath_change($event)" ></ion-input>
How to simulate the click on the ion-input
component using the div
?
my html code is:
<div (click) = "fileInput.click()">
<img src="assets/img/camera_button.png" [ngStyle]="{'position': 'fixed', 'top': '30vw', 'left': '32vw', 'height': '30px', 'color': '#0080FF'}">
<ion-input #fileInput type="file" accept="image/*" id="fileInput" [(ngModel)]="imageFilePath" (ionChange)="imageFilePath_change($event)" ></ion-input>
<span [ngStyle]="{'position': 'fixed', 'top': '32vw', 'left': '42vw', 'color': '#0080FF'}">{{ 'addMorePhotosBtn' | translate }}</span>
</div>
the error is:
TypeError: jit_nodeValue_20(...).click is not a function
Upvotes: 0
Views: 586
Reputation: 1863
Here is an my working Example for an file while clicking div.
Html File
<ion-list>
<ion-item (click)="onImageClick()">
<div>
<ion-icon ios="ios-add-circle" md="md-add-circle"></ion-icon>
Add Files
</div>
</ion-item>
</ion-list>
Typescript File
public onImageClick() {
let input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*'); //you can change also file type as **'file/*'**
input.setAttribute("multiple", ""); // If you dont want multiple select file pls remove this line
input.addEventListener('change', (event: any) => {
let fileList: File[] = event.target.files;
console.log("File List Object Value",fileList);
});
input.click();
}
Worked perfect for me tested.
Upvotes: 1