I have a html code like this with template reference variable for app-image-upload-component
<div *ngFor="let image of images"; let i = index>
<app-image-upload #imageUpload (click)="uploadImage(i)" (image)="setImageData($event, i)">
<img src="assets/img/camera-img.png" alt="img">
<h4>Upload Image</h4>
</app-image-upload>
</div>
Then in my typescript code, i am doing something like this
@ViewChild('imageUpload') imageUpload: ImageUploadComponent;
uploadImage(index) {
console.log('index', index);
this.imageUpload.showImageBrowseDlg();
}
When i fire click event on app-image-upload
, then it always shows index value 0
, no matter what is the index of *ngFor
.
I know this is happening because #imageUpload
is refrencing only to the first element of ngFor
, so is there a way to reference all elements of *ngFor
differently and to use them, as required in my code.