Unable to display text overlay on image in AngularJS

I am experiencing an issue with displaying captions on image modals.

    .controller('HomeController',['dataProvider','$scope','$location', '$modal', '$log', 'authService',
    function(dataProvider, $scope, $location,$modal, $log, authService){
        $scope.imageurl = [
            {
                'url': '/uploads/home/tenda kerucut.jpg',
                'thumbUrl': '/uploads/home/tenda kerucut.jpg',
                'caption': 'Tenda Kerucut',
                'size': 'Ukuran 3x3 m, 5x5 m'
            },
            {
                'url': '/uploads/home/tenda konvensional.jpg',
                'thumbUrl': '/uploads/home/tenda konvensional.jpg',
                'caption': 'Tenda Konvensional',
                'size': ''
            }
        ];

        $scope.open = function (item) {
            var modalInstance = $modal.open({
                templateUrl: '/partials/layouts/modal-home.html',
                controller: 'ModalInstanceCtrl',
                resolve: {
                    imageurl: function(){
                        return item;
                    }
                }
            });
        };

        $scope.toggleAnimation = function () {
            $scope.animationsEnabled = !$scope.animationsEnabled;
        };
}])

.controller('ModalInstanceCtrl', function ($scope, $modalInstance, imageurl) {
    $scope.item = imageurl;
});

This is my view

<div class="ui-product-thumbs grid-33" ng-repeat="image in imageurl">
            <a ng-click="open(image.url)">
                <img ng-src="{{image.thumbUrl}}" class="img-thumbnail" alt="">
            </a>
            <div class="ui-product-info">
                <p>{{image.caption}}</p>
                <div class="text-center">{{image.size}}</div>
            </div>
        </div>

and this is my modal

<div class="modal-body">
    <img class="img-full-width" ng-src="{{item}}">
    <p>{{image.size}}</p>
</div>

When I run the codes, the caption of the image does not show up on the modal. Can someone please assist me in resolving this issue? How can I display the caption on the modal when it is clicked?

Answer №1

Here's a more streamlined approach:

To start, make the necessary adjustment to your <a> tag by switching it to ng-click="open(image)" in order to pass the entire object rather than just the URL.

Next, within your HomeController...

$scope.open = function(image) {
    $modal.open({
        templateUrl: '/partials/layouts/modal-home.html',
        controller: function($scope) {
            $scope.image = image;
        }
    });
};

Subsequently, your modal template can utilize {{image.url}}, {{image.caption}}, and any other properties specific to the image object, such as:

<div class="modal-body">
    <img class="img-full-width" ng-src="{{::image.url}}">
    <p>{{::image.caption}}</p>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Accessing PHP output within Jquery

Even though I know PHP is a server-side script and JavaScript is client-side, I encountered an issue. I struggled to bypass browser security when making an AJAX request to another domain. Feeling lost, I decided to turn to PHP for help. The challenge I f ...

Struggling to find the definition of a Typescript decorator after importing it from a separate file

Consider the following scenario: decorator.ts export function logStuff(target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) { return { value: function (...args: any[]) { args.push("Another argument ...

Organize your blog content by utilizing post IDs as the designated id attribute

What is the best way to format blog posts and comments in HTML so that I can easily manipulate them later using jQuery/Javascript for tasks like updating, deleting, or making Ajax calls? I am considering using the IDs (primary keys in the database) of the ...

Having problems with loading @font-face in Ionic Framework Android app build?

While working on an app in Ionic Framework, I encountered a peculiar issue. https://i.stack.imgur.com/xk8uD.png In my Ionic Framework application, I am importing @font-face and running the app on an Android device (Galaxy SIII). Strangely, the font (Mont ...

Change the value of the material slide toggle according to the user's response to the JavaScript 'confirm' dialogue

I am currently working on implementing an Angular Material Slide Toggle feature. I want to display a confirmation message if the user tries to switch the toggle from true to false, ensuring they really intend to do this. If the user chooses to cancel, I&ap ...

Implementing React and Material UI: Maximizing Vertical Space Usage for a Box Component

Currently, I am working on a web application using React combined with Material UI. Within my code snippet below, you will see three Box components in play. Box 1 and Box 3 have specific heights set, but I am looking for a way to make Box 2 occupy the re ...

Create a list of items with checkboxes next to each that can be repeated using PdfMake

Incorporating pdfMake into my project, I am trying to display text next to an image and replicate this section in my docDefinition. The issue arises when I attempt to repeat this part using the following code snippet: { columns: [ { ...

Accessing a parent class constructor object in NodeJS from the Child Class

I'm currently working on creating a Controller Class that will handle the initialization of all my routes using ExpressJS. Below is a simple example of what I have so far: class Test extends Controller { constructor(App) { const Routes = [ ...

Can someone suggest a method for deciphering hexadecimal code used in JavaScript?

How can I gain an understanding of this code and convert it into simple javascript? Can someone assist me in deciphering the code or transforming it back to its original script? If someone obfuscated the javascript, what type of method should we use to de ...

"Learn the trick to replace the Ctrl + N shortcut in Firefox and initiate an AJAX request

Note: The answer provided by Juan Mendes has been selected as the best answer for my situation due to its usefulness. AxGryndr also offered valuable information, so I recommend reading both answers as they are beneficial in different scenarios. Thank you t ...

Is it possible to strip double quotes from link title attributes by using expression data?

Trying to pass the link title attribute for "Tags". The Tag value should be an array and now attempting to remove double quotes from the link title attribute. Upon hovering, currently getting: - ["text", "text 1", "text 2"]. Expected format (Text Capita ...

Encountering the error of receiving "$ undefined," despite making a reference to the library

I have included the JQuery library in the following way: <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script> Despite trying to download the library and include it locally in my project, I ...

Code Wizard

I am currently working on a project to develop an HTML editor. How it Needs to Function Elements Inside: Text Area - Used for typing HTML as text Iframe - Displays the typed HTML as real [renders string HTML to UI] Various Buttons Functionality: When ...

Updating component (`App`) during the rendering of another component is not allowed

I have encountered an issue with a react component that I am struggling to resolve. It involves a radial knob control, similar to a slider, and I am trying to achieve two main objectives: Adjust the knob and pass its value up to the parent component for ...

JavaScript classList.remove function experiencing inconsistencies

Take a look at this fiddle: JSFiddle The HTML code: <table class="myTable"> <tr> <th>Some text</th> <td class="align"> <span class=" someStyle">1</span>/<span class="otherStyle">15</span& ...

The trio of Meteor, Angular, and the Allow/Deny feature

Feeling a little stuck here. I've implemented the Allow deny rules but they seem to not be working no matter what variations I try. Currently, this is the code block I have: Players.allow({ insert: function(userId, doc){ return true; ...

Create a typescript class object

My journey with Typescript is just beginning as I delve into using it alongside Ionic. Coming from a background in Java, I'm finding the syntax and approach quite different and challenging. One area that's giving me trouble is creating new object ...

Utilizing MongoDB and Express to access collections within a controller

Is there a way to access the collection in the controller using mongodb and express? I came across this code snippet in the mongodb documentation db.getCollection("countries");, but how do you import the database name: db into a controller? serv ...

Transform User's Regex Output into Uppercase

My nodejs program allows users to input text and apply their own regular expressions for editing. I want users to have the option to capitalize or lowercase text as well. For example, if a user enters "StackOverflow is great!" with the regex (.) set to be ...

Tips for modifying date format in Angular 8

My datepicker for a date column is displaying the incorrect date format after submission. I am looking to change this format to the correct one. I am working with bsConfig bootstrap in Angular 8, but I am unsure of how to modify the date format. The back ...