Utilizing Angular's ng-repeat directive to dynamically generate images, with the added functionality of attempting to

I am utilizing angular-drupal to fetch data from my backend built on Drupal. My objective is to create an image gallery using the default endpoints provided by the services module. I make a call to node load to retrieve a specific node, then I extract the images attached to that node, iterate through them, and store them in an array.

Within my view, I utilize ng-repeat to loop through my loadedImages array, extract the file uri, and display the images accordingly.

The problem arises when ngRepeat immediately triggers, attempting to render the images before the promise for each one is resolved. This results in a forbidden GET error appearing at the top of the console, indicating that the view is trying to render an image with just the placeholder:-

GET http://localhost/headless-test/app/%7B%7B::val.uri_full%7D%7D 403 (Forbidden)

What would be the best approach to address this issue? I want to prevent ng-repeat from rendering anything until my array has been populated - or so I believe that's the root cause. Any assistance on this matter would be greatly appreciated. Additionally, it's worth noting that the functionality works as expected; however, the presence of the GET error in the console is undesirable.

Snippet of Controller code:

drupal.node_load(12).then(function(node) {
        console.log(node, "node returned");
        vm.loadedImages = [];
        for (var i = 0; i < node.field_test_image_3.und.length; i++) {
            drupal.file_load(node.field_test_image_3.und[i].fid).then(function(file) {
                vm.loadedImages.push(file);
                console.log(vm.loadedImages, "loaded images");
            });
        }
});

View section:

<div ng-cloak>
    {{::vm.loadedImages}}
    <div ng-repeat="(key, val) in vm.loadedImages">
        <img src="{{::val.uri_full}}" />
    </div>
</div>

Answer №1

My problem was resolved by simply changing the 'src' attribute to 'ng-src' in the image tag. I should have done a more thorough search on Google.

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 values returned by a NodeJS script in the Python shell are identical to those returned by Node

The following program was developed to address an issue in another application. In this program, a Python script is called from Node.js to perform a task. The Python script returns results that are then used in Node.js. NodeJS : var pythonShell = require ...

Is it feasible to verify for vacant dates with a single click?

Is there a way to determine if a date value is empty, and if it is, display a popup indicating so? After some research, I stumbled upon a similar issue where the date value was always filled with a default "mm/dd/yyyy" value. The solution provided involv ...

Passing variables from AJAX response to PHP using a passthru function

In my PHP file, I have implemented a functionality where certain checkboxes are checked and upon clicking a button, a JavaScript file is triggered. The JavaScript code snippet used is as follows: $.ajax ({ type: "POST", url: "decisionExec.php", ...

Navigating through the directories in PUG using the absolute path

Referring to the docs for PUG (), it states: If a path is absolute (example: include /root.pug), it gets resolved by prepending options.basedir. Otherwise, paths are resolved in relation to the file being compiled. To clarify, I understand that this in ...

Determine the moment at which the input is altered by adjusting the slider

I'm encountering an issue with making this work. My goal is to calculate input bmi_val whenever one of the other 2 inputs is modified. These inputs can be changed either directly by the user (entering a value into one of them) or through a jQuery sli ...

"Exploring the power of asynchronous programming with dynamic async await in

I am currently working on creating a versatile function that can dynamically call async functions. //passing the controller and functionName (string) function asyncAwaitCaller(controller, functionName) { let result = await controller[functionName]; } ...

How to dynamically retrieve submitted form data using AngularJS

Currently, I am dealing with a project involving angularjs and magento. The challenge I am facing is that in magento, I am unable to add ng-model to each form element due to them being created dynamically. To retrieve the submitted data using jQuery, I hav ...

AngularJS - A pagination demonstration incorporating intelligent logic inspired by Google's approach

I struggled to implement a paging solution that I came across online. The issue seems to be related to the timing of function calls, specifically how the setPage function is triggered before all data is retrieved, causing it to not properly determine the t ...

Loading CSS files conditionally in Angular2's index.html

Currently, my index.html page features a dark theme: <base href="/"> <html> <head> <title>XXX</title> </head> <body> <link rel="stylesheet" type="text/css" href="assets/dark_room.css"> <my-app ...

Are there any discussions underway about updating JSON standards to officially permit unquoted property names?

Technically speaking, the following JSON is considered invalid: { color: "blue", size: 14 } This is because according to the specification, property names like "color" and "size" should be enclosed in quotes, like this: { "color": "blue", "size" ...

Is it possible to swap out the content within a <div> element with an external piece of HTML code using JQuery or JavaScript whenever the viewport dimensions are adjusted?

<html> <head> </head> function () { var viewportWidth = $(window).width(); if (viewportWidth < 700) { $('#wrapper').load('A.html'); }; <body> &l ...

The isOpen State in AngularJS Accordion Component

Is it possible to determine if an accordion-group is open or closed without using the isOpen directive? I am curious if there is a way to access this information solely through HTML. I have experimented with two-way binding to store the state, but this app ...

Create an Android application using Node.js

While developing my mobile application, I am utilizing html5 with node.js to create a chat box for users connected on the same wireless network. However, I encounter an issue when coding on my desktop using node.js software. How can I overcome this challen ...

Tips for enabling browser back and forward functionality in a one-page website design

Building on the previous discussion about optimizing a horizontal sliding layout (Most efficient way to do a horizontal sliding layout), I'm curious if it's feasible to enable the back and forward buttons in the browser when implementing a single ...

Jest test encounters an error due to an unexpected token, looking for a semicolon

I've been working on a Node project that utilizes Typescript and Jest. Here's the current project structure I have: https://i.stack.imgur.com/TFgdQ.png Along with this tsconfig.json file "compilerOptions": { "target": "ES2017", "modu ...

Incorporating Bootstrap Navbar into a create-react-app project

I recently created a new project using create-react-app. To incorporate Bootstrap into my project, I followed these steps: npm install --save bootstrap@3 Next, I imported Bootstrap in my root file index.js: import 'bootstrap/dist/css/bootstrap.css& ...

What is the best way to keep vue-meta up to date when the route or URL

The issue I am facing is that the meta data on my website does not update when the route changes. Even though the route has a watch function that updates the view correctly, the metaInfo() method from vue-meta fails to keep up with the changes. Below is an ...

Steps for formatting a date from the date object in the ng-model:

I am extracting date values using the ng-model directive in my controller. My goal is to display the date in the format 10-22-2013, however, it is currently showing up as 10/22/2013. How can I correctly format the date in this scenario? JavaScript : ang ...

Creating an input field within a basic jQuery dialog box is not possible

Can anyone assist me in adding an input box to my dialog box? I am working with jquery-ui.js. Here is the code I currently have: $(document).on("click",".savebtn",function(). { var id = $(this).attr("id"); $.dialog({ ...

When using Next.js and Express.js together, CORS error may occur, causing API queries to only function properly during build

I am currently working on a project that involves using Next.js for the front-end and Express.js for the back-end. Front-end Setup The 'pages' directory contains an 'index.js' file where I have implemented the following code snippet: ...