Last active
July 31, 2022 13:34
-
-
Save francoishill/ed4286d2ad3c8ffd5ea0 to your computer and use it in GitHub Desktop.
Modal image in AngularJS and UI Bootstrap 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $scope.openModalImage = function (imageSrc, imageDescription) { | |
| $modal.open({ | |
| templateUrl: "path/to/modalImage.html", | |
| resolve: { | |
| imageSrcToUse: function () { | |
| return imageSrc; | |
| }, | |
| imageDescriptionToUse: function () { | |
| return imageDescription; | |
| } | |
| }, | |
| controller: [ | |
| "$scope", "imageSrcToUse", "imageDescriptionToUse", | |
| function ($scope, imageSrcToUse, imageDescriptionToUse) { | |
| $scope.ImageSrc = imageSrcToUse; | |
| return $scope.ImageDescription = imageDescriptionToUse; | |
| } | |
| ] | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="modalImage"> | |
| <div class="modal-header"> | |
| {{selectedImg.header}} | |
| <button ng-click="$dismiss()" class="close pull-right" aria-hidden="true">×</button> | |
| <div class="clearfix"></div> | |
| </div> | |
| <div class="modal-body"> | |
| <div class="image-wrapper"> | |
| <a ng-href="{{ImageSrc}}" target="_blank"> | |
| <img ng-src={{ImageSrc}}> | |
| </a> | |
| </div> | |
| <div class="text-muted image-description"> | |
| {{ImageDescription}} | |
| </div> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .modalImage .image-wrapper { | |
| text-align: center; | |
| } | |
| .modalImage .image-wrapper img { | |
| max-width: 560px; | |
| max-height: 560px; | |
| } | |
| .modalImage .image-description { | |
| text-align: center; | |
| margin-top: 10px; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <img ng-src="{{image-1-source}}" | |
| alt="{{image-1-name}}" | |
| ng-click="openModalImage(image-1-source, image-1-name)"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment