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

The State Hook error "state variable is not defined" arises due to an issue with the state declaration in

function Header() { const [keys, setKeys] = useState([]); //custom addition const first = (e) => { var result = new Map() axios.post('http://localhost:8000/' + query) .then(function(response){ var content ...

Dealing with the 404 error for a missing resource in ocLazyLoad

I am seeking guidance on how to handle resource loading errors in ocLazyLoading. I have attempted to load some resources within the resolve section of my $stateProvider. One file, ctrl.js, loads successfully. However, another file, iam-not-there.js, fails ...

Background and border presentation issues arising from CSS conflict

While working on a webpage, I encountered a design conflict within a div that contains a group of other div elements. The current appearance can be seen at , and the desired look is shown in the image here: enter image description here ...

How to access a component attribute in a JavaScript library method in Angular 8

Within my Angular project, I am utilizing Semantic UI with the code snippet below: componentProperty: boolean = false; ngOnInit() { (<any>$('.ui.dropdown')).dropdown(); (<any>$('.ui.input')).popup({ ...

The outer DIV will envelop and grow taller in conjunction with the inner DIV

Could use a little help here. Thank you :) I'm having trouble figuring out how to get the outer div to wrap around the inner div and expand upwards with the content inside the inner editable div. The inner div should expand from bottom to top, and t ...

Guide to utilizing exact matching functionality in ExpressJs router

In my ExpressJs application, I have defined two routes like so: router.get("/task/", Controller.retrieveAll); router.get("/task/seed/", Controller.seed); When I make a request to /task/seed/, the Controller.retrieveAll function is call ...

Space between Logo Header and Navigation Bar

Recently, I attempted to create a new header with a responsive logo and menu. After seeking guidance from StackOverflow experts, everything seems to be functioning correctly now. However, I am facing an issue regarding the gap between the header and navba ...

jQuery GetJson fails to execute success function

I'm trying to use this code for an Ajax request to a JSON file: let formData = $("#myform").serialize(); $.getJSON("/files/data.json?" + formData, function(response){ alert(response); } ); However, there are no errors and the alert is n ...

Unclear when notifying div content

After creating a PHP page, I encountered an issue while trying to select the inner text of a div and alert it with jQuery. Instead of getting the expected result, it keeps alerting "undefined." What could possibly be causing this? Here is the code snippet ...

Implementing npm in your project: practical tips for optimal usage

Recently set up a project in my web directory and successfully tested a basic "Hello World" example. After that, I proceeded to install Node.js and Grunt for my development environment. Next step was running the command: npm install angular-ui-boot ...

Cover the entire screen with a solid background color and adjust the text size accordingly

I'm encountering two issues. Despite my efforts to adjust multiple containers, the background colour #eee simply won't reach the bottom of the screen. I've even tried setting the HTML height to 100%, but to no avail. Even though I&apos ...

Data within React/Next.js will remain unchanged even after a link has been clicked

When using Next.js and clicking on a Link, the new page URL will open as "/component/product". However, the product data is not updated in the Redux store. The page needs to be refreshed in order to update the state data. import Link from "n ...

Retrieving the values of a particular row in a table multiple times using angular JS and filters

I am currently making a call to an API that will provide me with a JSON object. From this JSON object, I am extracting values based on certain conditions and displaying them in a table using AngularJS. The challenge I am facing now is retrieving the data f ...

Is it possible for me to repurpose the existing REST API and database?

My website is built with angularjs, html, and a rest api on the backend, using mysql as the database. Now I want to convert it into an app and am considering using phonegap. Is it possible to use the same database and rest api for developing the app? ...

Is there a way to make JavaScript function properly with PHP-generated content?

I have a PHP file that loads a variety of forms depending on an identifier passed through a GET request. Everything is functioning properly, except for my JavaScript/jQuery code. Is there a way I can refresh the JavaScript to make it work with the form? ...

Experiencing the "Module not found" issue while incorporating SCSS into React applications

I attempted to apply a SCSS style to my "Logo.js" component, but I am still unable to resolve the error that keeps popping up: ERROR in ./src/components/Logo/Logo.js 5:0-19 Module not found: Error: Can't locate 'logo.scss' in '/Users/a ...

Trouble with loading scripts after transitioning to a new page with AJAX (Barba.js)

Exploring the potential of using AJAX for smooth page transitions. Tried two different methods so far: manually coded transition from () and Barba.js approach (). With both methods, scripts work on initial load but fail to execute when navigating to anot ...

When using Material UI, it is not possible to apply the text-overflow: ellipsis and overflow: hidden properties to multiple

I am new to material UI and here is the current state of my website: view reality of current website This is what I am expecting it to be: what I envision it becoming From the images above, you can see that I want the text inside the circle to be shorten ...

Unlocking the Potential: Unveiling the Art of Activating Navigation in Single-Page Websites

I am currently developing a one-page website. In order to enhance the navigation experience, I want the active section or "page" to be visually highlighted in the navigation bar. At present, when I click on a link, it successfully displays with an underlin ...

I'm curious about the significance of the "packages" property in the requireJs config. Can someone explain how it functions?

I'm currently trying to grasp the concept of requireJs and its functionality. In my exploration, I encountered a configuration property called "packages." From what I gather, 'packages' is intended for specifying a complete folder or module ...