List displaying empty results

Question has been updated with a solution. I have successfully retrieved a JSON feed from .

Although the JSON data is appearing in my scope and displaying in my pre tags, it's not populating in my ng-repeat as expected.

app.controller('InstagramCtrl', ['$scope', '$http',
function($scope, $http) {
    $scope.items = [];
    $http.get('https://filters.rocks/embed/466.json').then(function(response) {
            $scope.items = response;
            instagramSuccess($scope, $scope.items);

    });

    var instagramSuccess = function(scope, response) {
        if (response.data.length <= 0) {
            $scope.error = response.meta.error_type + ' | ' + response.meta.error_message;
            return;
        }
        if (response.data.length > 0) {
            $scope.items = response.data;

        } else {
            $scope.error = "This hashtag has returned no results";
        }
    };

}
]);

HTML

    <div class="container" ng-controller="InstagramCtrl">

    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">

                </div>
                <div class="panel-body">
                    <ul class="instagram-list" ng-repeat="item in items">    
                        <li>
                            <small>{{item.data.feed.id}}</small>
                            <img ng-src="{{item.data.feed.approved_images.medium}}" width="250">
                        </li>

                    </ul>                       
                </div>
                <pre> filter.rocks {{ items | json }} </pre>
            </div>
        </div>           
    </div>

Update After incorporating suggestions from various sources, here is the revised code: Controller

$scope.items = [];

      $http.get('https://filters.rocks/embed/466.json').then(function(response) {

            instagramSuccess(response);

    });

    var instagramSuccess = function(response) {
        if (!response.data) {
            $scope.error = response.meta.error_type + ' | ' + response.meta.error_message;
            return;
        }
      
        if (response.data && response.data.feed && response.data.feed.approved_images && response.data.feed.approved_images.length ) {
            $scope.items = response.data.feed.approved_images;

        } else {
            $scope.error = "This hashtag has returned no results";
        }
    };

HTML

                 <ul class="instagram-list" ng-repeat="item in items">    
                        <li class="instagram-item">
                            <small style="color:blue;">{{item.id}}</small>
                            <div bg-img="{{item.medium}}" width="250"></div>
                        </li>
                    </ul>

Answer №1

As pointed out by madhairsilence, it seems like you are treating items as an array when it is not. You might want to iterate through the approved images like this:

<ul class="instagram-list" ng-repeat="item in items.feed.approved_images">    
    <li>
        <small>{{item.id}}</small>
        <img ng-src="{{item.medium}}" width="250">
    </li>
</ul>

Answer №2

Revise the HTML by replacing the content below without modifying the controller. Ensure you correct the item being looped through.

   <div class="panel-body">
          <ul class="instagram-list" ng-repeat="item in data.feed.approved_images">    
               <li>
                  <small>{{item.id}}</small>
                  <img ng-src="{{item.medium}}" width="250">
               </li>

         </ul>                       
    </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

Angular 2 TypeScript: Accelerating the Increment Number Speed

I'm working with a function in Angular 4 that is triggered when the arrow down key is pressed. Each time the arrow down key is hit, the counter increments by 1. In this function, I need to run another function if the counter reaches a certain speed. ...

How can I code in React to make one button change color while the others remain a different color, instead of all having the same color?

I developed a quiz application that changes the color of answer buttons based on user selection. If the user clicks the correct answer button, it turns green, and if they click the wrong answer, it turns red with the correct answer displayed in green. Howe ...

Locate the upper and lower limits within an array

I'm currently working on extracting the upper and lower boundaries for a numeric value within an array. const boundaries = [15, 30, 45, 60, 75, 90]; const age = 22; In the given example, the expected result would be: [15, 30] If the value matches ...

Able to retrieve individual elements from an array, but not able to loop through them

I am facing an issue with my code where I have two arrays - one containing URLs and the other external data. These two arrays are perfectly aligned, but when I try to access them in a loop using AJAX requests, only the first element of the URL array prints ...

Using a React PureComponent to pass parameters from a Child component

I am facing an issue with my TodosList component that displays a list of individual Todo components. Below is the code snippet for the Todo component: export class Todo extends React.PureComponent { render() { return ( <li onClick={this.pr ...

How can I effectively display the names of the months in AngularJS?

When working on an Angularjs project, what is the most efficient way to include the titles of the months in HTML? Here is a snippet of my current hard-coded solution that I am looking to improve: <div> <div class="col-xs-3"> <d ...

Mapping API for JavaScript, converting coordinates into precise locations

I have two coordinates: 54.674705589 and 25.289369548. I want to place these coordinates on a map when the button is clicked, similar to this example. However, the example provided is for addresses, not coordinates. Is it possible to modify this example t ...

Utilize jq to transform AWS SSM JSON data into environment variables

After conducting thorough research, I've made significant progress towards my goal, but I'm encountering difficulties with adjusting the jq output to meet the necessary requirements, particularly with splitting a string. My objective is to trans ...

Validating an Element Directive in AngularJS: A Step-by-Step Guide

I have developed a directive for handling numbers function numberInputDirective() { return { restrict: 'E', scope: { model: '=', disabled: '=?', decimals: ...

Utilize JavaScript to Replace KeyPress Event on Input Field

While attempting to substitute the key press of "K" with "Z" in an input field, I managed to accomplish it successfully. However, there seems to be a slight delay that causes the user to observe the transition from "K" to "Z". Below is the code that I use ...

The functionality of two-way data binding seems to be malfunctioning within the directive

This is my first attempt at creating a directive in AngularJS and I am still learning the ropes. I'm currently experimenting with integrating Bootstrap Year Calendar with AngularJS. The Bootstrap Year Calendar is a jQuery plug-in designed to display ...

Steps for resolving the issue "Error: Module not found 'C:Users odri odejs_paypalsrcindex.js'" in Node.js

As I attempt to launch my Node.js project, I'm running into a module resolution error that reads as follows: PS C:\Users\rodri\nodejs_paypal> npm run dev <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=" ...

Encountered an error while trying to initialize ng-init in Angular, specifically when including PHP

I have a PHP variable called $output. When I use echo json_encode($output), the output looks like this: [{ "title": null }, { "title": "a b c" }, { "title": "d e f" }, { "title": "d f g" }, { "title": "f g d" }] It appears to be corre ...

Ways to adjust brightness of a color using jquery

I have implemented color swatches and a slider to adjust the lightness and darkness of colors. I am seeking a way to change the lightness of the color based on the slider value. Here is what I have attempted: $("#darklight").slider({ range: "min", ...

Could json.loads() be exploited for executing arbitrary code?

Does the json.loads function from Python's built-in json module pose any risk of allowing arbitrary code execution or other security vulnerabilities? I need to process JSON data from sources that may not be trustworthy. ...

Parsing a JSON request using Restlet

My goal is to create a basic observatory app for keeping track of books and other items using restlet. So far, I have successfully implemented some simple GET requests, but I am facing an issue with POST requests. The specific problem I am encountering is ...

Typescript - filtering out null values from JSON object

I am facing an issue with my service method that saves a date on the server. When this method sends the date to the server, it includes fields with null values in the JSON. How can I exclude these fields with null values? public create<T>(post: any) ...

Creating a dropdown menu utilizing JavaScript/jQuery arrays

Looking to create an HTML select menu using a JavaScript array where the keys are used as values for options. The challenge is when entering numbers as keys, they should be accepted in the code. a([selected="No of rooms", 1="1", 2="2", 3="3", 4="4", 5="5" ...

The Next.js build failed due to the absence of the required "slug" parameter being passed as a string

I'm currently working on setting up a blog using Next.js and TypeScript, and I've encountered an issue with [slug].tsx. The error message I'm receiving is: Build error occurred Error: A required parameter (slug) was not provided as a strin ...

The provider for authentication, which is linked to the AuthenticationService and subsequently to the loginControl, is currently unidentified

Attempting to implement an authentication service in my application, I encountered an error when trying to call it within my controller: !JavaScript ERROR: [$injector:unpr] Unknown provider: AuthenticationServiceProvider <- AuthenticationService <- ...