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

Encountering the following error: Exceeded maximum call stack size limit

Currently, I am attempting to tackle a specific problem on LeetCode. This particular challenge involves calculating the power of x. However, upon executing my solution, an error message is displayed: RangeError: Maximum call stack size exceeded Here&apos ...

Using babel with node.js version 18 allows you to easily import modules with various extensions and run them from the build folder configured with commonJS. Ensure that you have specified "type:module"

I'm currently utilizing Node.JS version 18.20.4 alongside Babel. Below is my babel.config.json: { "presets": [ [ "@babel/preset-env", { "targets": { "node": 18 }, ...

An uncaught exception has occurred: An error was encountered indicating that the specified path is not valid for either posix or windows systems, and it appears that there is no 'join' method defined in the

I am currently working with nextjs version 13.5.6 using the app router and app directory. This issue arises during the compilation of the route app/(home)/page.js. The folder and file structure within the app folder is as follows: app/ -(home)/page.js -ser ...

How can I ensure that an item stays in place within a vertically sortable list using Dndkit? (I am also considering alternative drag-and-drop libraries)

Let's say for instance that 5 was marked as frozen. If 4 was then moved below 6, the change in arrangement would be as follows: before: https://i.sstatic.net/iVZFtAmj.png after: https://i.sstatic.net/tCq09Qgy.png My current approach involves us ...

jQuery floating sidebar that dynamically adjusts position based on content overflow

I've come across an interesting scenario with a fiddle that I'm working on: http://jsfiddle.net/yFjtt/1/ The main concept is to allow users to scroll past the header and have the sidebar 'stick' in place as they continue scrolling down ...

What is the process for setting a cookie that allows for reading from the same domain with a different port?

After setting my cookie in C# code with Request.Cookie["NTLogin"].Value="XYZ", I encountered an issue when attempting to read this cookie from a new application built in Angular JS. To access the cookie, I used $cookies.get('UserNTLogin'). The p ...

Troubleshooting problem with AJAX returning JSON values

Utilizing a jQuery post request in the following manner: $.post('url', {data: some_data}, function(data, textStatus, jqXHR) { console.log(data); //for debugging console.log(data.status == "ok"); //for debugging .... }); The url hits ...

Error in Express Session: Property 'signin' is not found in type 'Session & Partial<SessionData>'. Code: 2339

I received the following Error Code: Property 'signin' does not exist on type 'Session & Partial<SessionData>'. (2339) About My Application src/index.ts import "reflect-metadata"; import express = require("expr ...

Steps to incorporate / insert Angular directive in an application

In my app, the main.js file is located in the root folder. -app |_ routes.js |_ main.js -components |_directives |_abc-directive.js I am trying to figure out how to define a directive that can be accessed from a different folder. This is what I at ...

Tips for retrieving data from an Excel spreadsheet on an HTML/CSS webpage

I have a single HTML template at this location: . The current page is tailored for the state of Arkansas in the US, but I now need to replicate the design for all 50 states. Each state page will have the same layout, but different content specific to that ...

Error in code - message gets sent immediately instead of waiting for timeout to occur

There seems to be an issue with the code where the message is sent instantly instead of waiting for the specified timeout duration. Based on the code, it should wait for the time mentioned in the message. I'm puzzled as to why it's not functioni ...

Encountered a buildkite error stating that the plugins file is either missing or invalid, resulting in a failure to locate the module 'xlsx' when executing a cypress test. Strangely

Encountering an issue while running my Cypress test on Buildkite. Here's the error message: Status: Downloaded newer image for cypress/included:6.1.0 [2022-01-31T10:32:13Z] Your pluginsFile is set to /e2e/cypress/plugins/index.js, but either the fil ...

Clearing FullCalendar events when the month button is pressed: A step-by-step guide

What is the best way to hide ONLY events on a calendar? I was considering deleting all events when the user clicks the "month" button. How can I achieve this functionality? $scope.uiConfig = { calendar: { height: 450, editable: false, ...

Can halting an ajax function mid-process prevent it from finishing?

My objective is to convert a video using ffmpeg, which tends to take a considerable amount of time to complete. I'm considering sending an ajax request to the server for this task, but I don't want the user to have to wait until the video convers ...

Crafting dynamic parameters in the Express router - A step-by-step guide!

Original Code Example: const express = require('express'); const router = express.Router(); router.get('/data/:d1/:d2/:d3', require('../apifoo').foo); Route: /data/:d1/:d2/:d3 Path: /data/1/2/3 req.params : 'd1' : ...

Creating a CSS Grid with Scroll Snap functionality to mimic an iPhone screen in HTML

I have created an iPhone simulator using HTML. It's in German, but I can provide a translation if needed: // JavaScript code for various functionalities related to the iPhone interface /* CSS styling for the iPhone interface */ <meta name="v ...

How can I use AJAX to update a DIV when an image is swapped out?

I run an online radio station and I've been looking for a way to display album artwork for each song that plays. After setting up the ability to automatically upload the image of the currently playing song as "artwork.png" to a web server via FTP, I c ...

Chrome's inability to efficiently handle chunked responses in comparison to Firefox and Safari

I am currently working on a unique test node server that sends chunked responses every two seconds with the specified headers: response.setHeader('Content-Type', 'text/plain') response.setHeader('Transfer-Encoding', 'chu ...

switch out javaScript for selenium

I'm attempting to replace the JavaScript functionality of a web page using Selenium (in Java with Firefox Geckodriver, if that makes a difference). Consider this webpage: <HTML><HEAD></HEAD> <BODY> <DIV id="time">Ti ...

What is the best way to serialize a form with input files?

I'm facing a challenge with serializing and sending AJAX data from a form that includes a textarea and an input field for file uploads: <input type="file" name="files" file-input="files" multiple /> Can you help me with the correct way to ach ...