I have the following situation:
<input type="file" name="profilePicture" id="profilePicture" accept="image/*" (change)="onFileSelected($event)" style="display:none"/>
<img *ngIf="!this.profile.profilePic" src="...a static path..." />
<img *ngIf="this.profile.profilePic" [src]="this.profile.profilePic" />
and I would like to trigger the input file on one of the two images that are displayed in the img
tags, according with the ngIf
. This means that I want the upload window to open when I click on the image without having the standard input of type "file" as usual. My code, as I wrote it here, doesn't work. Can anybody explain me how to trigger the upload file from the image tag and hide the input tag instead?
EDIT
The onFileSelected
is only a function that processes the uploaded image and store the object in a temporary variable called profilePicture
:
onFileSelected(event) {
if (event.target.files.length > 0) {
this.profilePicture = event.target.files[0];
} else {
this.profilePicture = undefined;
}
}
profile
is instead an object which contains all the info related to the user.
EDIT II
I tested the code by using only one img tag. The following code doesn't work either:
<input type="file" accept="image/*" (change)="onFileSelected($event)" style="display:none"/>
<img [src]="'...the static path...'"/>
EDIT III
My problem is related to this question that address the same problem I have (and didn't help unfortunately).