How can I display the clicked image in a modal?
Implementation:
<a ng-click="openModal($event)" ng-style="{'background-image': 'url(assets/img/img-01.jpg)'}"><img src="assets/alpha-4x3.png"></a>
<a ng-click="openModal($event)" ng-style="{'background-image': 'url(assets/img/img-02.jpg)'}"><img src="assets/alpha-4x3.png"></a>
Code in Controller:
$scope.openModal = function($event) {
$scope.modal.show();
$scope.poppedUpImg = $event.target.style.backgroundImage;
};
Modal Template Content:
<ion-content class="p20">
<img ng-src="{{poppedUpImg}}" alt="">
</ion-content>
The current code is not functioning as expected. Any suggestions for improvement or alternative approaches are welcomed. The issue arises when an image is placed inside the anchor element, capturing clicks intended for the alpha image.
Edit/Update:
I found that @Sphinxxx's solution works well if the anchor contains text content. However, it does not work when an image is embedded within the anchor tag. Here is my adjusted implementation to resolve this issue.
$event.srcElement.parentElement.style.backgroundImage.split('("')[1].split('")')[0]