Troubleshooting problem with AngularJS ng-repeat

Seeking assistance with an angularjs issue as a newcomer to the platform. Building a photo gallery where the initial page displays thumbnail photos from twitter and instagram using ng-repeat loop. Hovering over an image fades it out, revealing a button for users to click, triggering a light box overlay with the full-size image. The latest version can be viewed online: . Below is the code snippet. Successfully developed the thumbnail display but facing challenges with the light-box feature, where only the first image in the collection appears regardless of which one is clicked. This seems to stem from an issue within ng-repeat loop. Images are stored in each object under mainImage.url, accessed through x.mainImage.url in the loop. Questioning why it's not functioning correctly and any assistance would be appreciated.

<style>
    * {
        box-sizing: border-box;
        font-family: sans-serif;
    }
    h1, 
    h2{
        margin-left:10px;
    }

    .outer-wrapper{
        overflow: hidden;
    }
    .inner-wrapper{
        display:inline-block;
        vertical-align:top;
        padding:5px;
        position:relative;
    }
    ...

    // AngularJS module, controller, and API calls
</script>

Answer №1

Concealing it using the id is not the correct approach, as the id should always be unique.

Here is a simple solution:

Follow these steps:

Include these styles as we will utilize an Angular directive called ng-class

.show {
    pointer-events: auto !important;
    opacity: 1 !important;
}
.hide{
    opacity: 0 !important; 
    pointer-events: none !important;
}

In your HTML file, utilize ng-init to establish a scope variable for your ng-repeat that manages the display/hide functionality. It's up to you to clean up the id's.

<div id="outer-wrapper" class="outer-wrapper">          
        <div id="inner-wrapper" class="inner-wrapper" ng-repeat="x in insideData" ng-init="show = false">
            <img ng-if="x.service=='Instagram'||(x.service=='Twitter' && x.mediaType=='image')" ng-src='{{x.thumbnails[0].url}}'>
            <div class="outer-caption" ng-if="x.service=='Twitter'&& x.mediaType!='image'">
                <div class="inner-caption">{{x.caption}}</div>
            </div>
            <div class="item-overlay-color"></div>
            <!--We do this because we don't have reference of show in the controller-->
            <div class="item-overlay-text" ng-click="show = true">VIEW</div>
            <!--In here we handle the show and hide-->
          <div id="page-overlay" class="page-overlay" ng-class="{'show': show, 'hide': !show}">
             <div class="text">
                 <img ng-src='{{x.mainImage.url}}'>
                 <span class="close" ng-click="show = false">X</span>
                 </div>
             </div>
        </div>
    </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

Exploring the capabilities of transform and duplex streams in NodeJS

Collecting data from an external source via Bluetooth Low Energy using NodeJS (noble module) and storing it in a JSON array file named fromSource.json: [ { "id": 1, "name": "foo", "value": 123 }, { "id": ...

Craft a stunning transparent border effect using CSS

I am trying to achieve a unique border effect for an element using CSS, where the transparency is maintained against the background: This is the desired outcome: https://i.stack.imgur.com/6Z1MU.png However, the border I am currently able to create looks ...

GeckoDriver Firefox and Protractor(Selenium) encountered a NoSuchWindowError due to the browsing context being discarded

I need assistance with running a basic test script using protractor. Environment: Node Version: v9.8.0 Protractor Version: 5.4.1 Angular Version: 1.x Browser(s): Mozilla Firefox 60.1.0 Operating System and Version: HELiOS release 6.10 Below is my config ...

Monitoring inbound and outbound traffic in express middleware

I am in the process of incorporating a logger into my Express application. This logger needs to record both requests and responses (including status codes and body content) for each request made. My initial approach involves creating a middleware function ...

Strange Firefox behavior with absolutely positioned div and percentage height

One of my projects includes a CSS modal dialog that is structured as follows div { position:fixed; top:50%; left:50%; margin:-26% 0 0 -26%; width:46%; height:46%; padding:3%; } Interestingly, this div appears centered in webkit browsers. Ho ...

Which is the preferable option for creating a circular daily planner: canvas or SVG?

As a novice programmer delving into the world of coding (or at least hoping to), I have a question regarding graphic tools in html5 for my latest project. My goal is to create a planner app using electron, with the unique twist that the planner form sho ...

The gradient applied to the svg <text> element is failing to function

I'm currently working with an SVG element and trying to incorporate a <text> element with a gradient. Interestingly, the same LinearGradient successfully applies to one SVG but not to another. My question is whether a gradient can be applied to ...

What are some effective methods to completely restrict cursor movement within a contenteditable div, regardless of any text insertion through JavaScript?

Recently, I encountered the following code snippet: document.getElementById("myDiv").addEventListener("keydown", function (e){ if (e.keyCode == 8) { this.innerHTML += "&#10240;".repeat(4); e.preventDefault(); } //moves cursor } ...

Exploring the powerful capabilities of utilizing state variables within styled components

I'm attempting to create a button that changes its state based on the value of a property within an object. Below is the styled component const Btn = styled.button` border-radius: ${props => props.theme.radius}; padding:5px 10px; backgroun ...

Minimize the screen dimensions and adjust the margins accordingly

Having a problem with responsive margins? Take a look at this site as an example: When I shrink the screen size, the margins decrease and smoothly transition from 4 to 2 columns. In my case, it does something similar but the issue is that the margin does ...

What could be causing an error with NextJS's getStaticPaths when running next build?

When attempting to use Next.js's SSG with getStaticPaths and getStaticProps, everything worked fine in development. However, upon running the build command, an error was thrown: A required parameter (id) was not provided as a string in getStaticPath ...

Issue with nested directive not triggering upon page load

I recently started working with AngularJS and came across an issue with nested directives. In my project, I have two directives: MainDir.js (function(){angular.module("mod").directive("mainDir", function(){ return { restrict: "E", scope: {}, ...

Conceal your password using HTML techniques

My goal is to hide passwords from being visible unless a user hovers directly over them. I've tried using the code below, but the hover effect isn't working as expected - either the password disappears completely or remains visible at all times. ...

How to send parameters to Bootstrap modal using a hyperlink

I need help confirming the deletion of a datatable row using a Bootstrap modal dialog. When a user clicks on the delete link, I want a modal to appear asking for confirmation. Here is my code: <c:forEach items="${equipes}" var="equ"> ...

Navigating through dropdown browser menus using VBA

I am looking to automate the process of looping through a dropdown list on a specific website and downloading the latest file for each entry. I have successfully opened the website and clicked the "submit" button, but I am struggling to find a solution to ...

Is there a way to determine the file size for uploading without using activexobject?

Can the file size of an uploading file be determined using Javascript without requiring an ActiveX object? The solution should work across all web browsers. ...

Paypal Payment Plans on a Monthly Basis Utilizing the Bootstrap Pricing Slider

I came across this fantastic Bootstrap Pricing Slider that I found originally at Within my Bootstrap Pricing Slider, there is a "total amount" calculated after some math, resulting in a final score. The slider includes a "Process" button which currently ...

What strategies work well for guiding individuals to different destinations based on their user roles, such as administrators and regular users?

In my CMS environment, I am facing a challenge with redirecting users who are not administrators or do not own the document they're trying to edit. The following code snippet is what I have implemented, but it seems that my administrators cannot acces ...

Guidance on incorporating static files with Spring MVC and Thymeleaf

I'm seeking guidance on how to properly incorporate static files such as CSS and images in my Spring MVC application using Thymeleaf. Despite researching extensively on this topic, I have not found a solution that works for me. Based on the recommenda ...

Managing the automatic download of a zip file through JQuery - A guide

When working with a REST API and creating a zip file for forced download, the task is to call the API by sending necessary POST data through JQuery to initiate the download. How can this goal be accomplished effectively? ...