Having difficulty displaying nested arrays in AngularJS

Understanding JSON Data in AngularJS

As I delve into the world of AngularJS, I've encountered a minor roadblock when it comes to fetching JSON data.

<html>

<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ODataResources/1.0.25/odataresources.min.js"></script>
</head>

<script>
  var app = angular.module('links', []);
  app.controller('feedLinks', function($scope, $http) {
    const BASE_URL = 'http://services.odata.org/V3/OData/OData.svc/'
    $http.get(BASE_URL)
      .then(function(response) {
        $scope.rawdata = response.data; // array with two elements - one link and an array with data
      });
  });
</script>

<body>
  <div class="container main-container">
    <div class="row">
      <div class="col menu">
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
          <a class="navbar-brand" href="#">Navbar</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarNav">
            <ul>
              <div ng-app="links" ng-controller="feedLinks">
                <li ng-repeat="element in rawdata">
                  {{ element }}
                  <a class="nav-link" href="{{ element.url }}">{{ element.name }}</a>
                </li>
              </div>
            </ul>
          </div>
        </nav>
      </div>
    </div>
  </div>
</body>

</html>

I'm facing difficulties as the JSON data is returning an array structure that includes both a single link and another nested array. As a result, extracting and displaying the nested array has proven to be challenging. Any guidance on this issue would be greatly appreciated.


Currently occupied on a call, please refer to the screenshot below:

Answer №1

Give this a shot:

<html>
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ODataResources/1.0.25/odataresources.min.js"></script>
  </head>

  <script>
    var app = angular.module('links', []);
    app.controller('feedLinks', function($scope, $http) {
        const BASE_URL = 'http://services.odata.org/V3/OData/OData.svc/'
        $http.get(BASE_URL)
        .then(function(response) {
            $scope.rawdata = response.data; //array with two elements - one link, and an array with data
        });
    });
  </script>

  <body>
        <div class="container main-container">
            <div class="row">
                <div class="col menu">
                    <nav class="navbar navbar-expand-lg navbar-light bg-light">
                        <a class="navbar-brand" href="#">Navbar</a>
                        <button class="navbar-toggler" type="button"
                                data-toggle="collapse"
                                data-target="#navbarNav"
                                aria-controls="navbarNav"
                                aria-expanded="false"
                                aria-label="Toggle navigation">
                            <span class="navbar-toggler-icon"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="navbarNav">
                        <ul>
                            <div ng-app="links" ng-controller="feedLinks">
                                <li ng-repeat="element in rawdata.value">
                                    <a class="nav-link" href="{{ element }}"> 
                                     {{ element.name }}
                                    </a>
                                </li>
                            </div>
                        </ul>
                      </div>
                    </nav>
                </div>
            </div>
        </div>
    </body>
</html>

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

Why is async await giving back a promise object instead of my intended value?

During an event triggered by a select element, I am trying to call a function named init(); Within the init() function, another function called getManifestJsonFilePath() is invoked. Inside the getManifestJsonFilePath() function, I am attempting to search ...

What could be causing this array to be blank?

In the process of working on a product feedback app using React for my portfolio, I encountered an unexpected issue. The problem arises in my SuggestionDetails component, where I am fetching the current id with useParams and filtering out the current produ ...

Splitting the string into individual characters using string.split("").map may cause layout issues on small devices

Shoutout to @pratik-wadekar for the amazing help in creating a working text animation. However, I encountered an issue when testing it on various screen sizes and mobile devices - the animated word plants breaks into pieces like PLA on one line and NTS on ...

Why is Puppeteer failing to download to the designated folder using "Page.setDownloadBehavior" in Windows?

When trying to download a file using Puppeteer, I found that the code works perfectly on a Mac OS machine but fails on a Windows machine. The code snippet I used is shown below: await page._client.send( 'Page.setDownloadBehavior', { beha ...

Selection of Dropdown results in PDF not loading

I am facing an issue with my function that selects a PDF from a dropdown list. Instead of loading and displaying the PDF, it only shows a blank modal. Any suggestions on how to fix this? <li> <a href="">Case Studies</a> <ul clas ...

"Discovering the magic behind leaflet js's method of fetching tiles directly from

If you imagine tiles being stored in a file system similar to the image shown below https://i.sstatic.net/6NryK.png You can take a quick look at this URL Take a look at the code var map = L.map('map').setView([0, 0], 2); L.tileLayer(& ...

Tips for updating page content without needing to refresh the page

Have you noticed on Foursquare's website: They have new feeds appearing automatically without the need to refresh the page. I'm working on a backend system to display user specific feeds. How can I achieve the same effect as Foursquare? ...

The test may detect a variable that was not initialized

I'm trying to understand why I get the error message "variable may not have been initialized" when testing (variable === "some text"), but I don't receive the same error when using (typeof passwordHashOrg !== 'undefined') The code that ...

How can I change the attributes of icon().abstract.children[0] in the fontawesome-svg-core api?

The issue at hand: The icon() function within the fontawesome-svg-core API is setting default properties for SVG children elements that require custom modifications. My objective: The outcome of the icon() method is an object with an "html" property, co ...

The 'checked' property cannot be bound to 'mat-button-toggle' as it is not recognized as a valid property in Angular 9

I am encountering an issue with my Angular 9 application. I have integrated angular-material and imported the MatCheckboxModule correctly in the module. Here is the version of the material package I am using: "@angular/material": "^10.2.0&q ...

Is there a way to retrieve database information and save it in a Json file to design a user interface grid with AngularJS, all without employing

I'm looking to display data from a database table in a grid view on an HTML page using AngularJS. I have a C# file and a Data Access Layer set up to retrieve the data in JSON format. How can I go about converting this JSON data into HTML for display o ...

In the matrix game, if a user chooses two balls of the same color, those two matching color patterns will be eliminated

I am currently working on a matrix game with the following condition: When a user selects two balls of the same color, they will destroy the two patterns with the same color. I have successfully implemented horizontal and vertical selection. However, I ...

Error code 70006 encountered in Typescript when attempting to reference a type as "any"

Currently, I am working on a React project that involves using TypeScript. This is quite new to me, and I have encountered a type error in one of my components... let dragStart = (e) => { let transferringData = e.dataTransfer.setData("text", e.tar ...

What is the best way to retrieve the value of scope.postresult in JavaScript within my HTML code?

I have the following code in my controller.js file where I am retrieving the value of "postresult". $scope.open= function(post) { $scope.postresult = post; } In the HTML snippet below, I am loading a DISQUS thread and need to access the "postr ...

A step-by-step guide to integrating connect-multiparty with Sails.js

After reviewing an example that utilizes Node.js (Express.js) found here: https://github.com/danialfarid/ng-file-upload/wiki/Node-example I am interested in creating a service within Sails.js that can be integrated into Angular.js (View). This service sh ...

The primary controller in AngularJS

I am currently facing an issue where I am unable to load a page to its home page. When I first load the page, it redirects me to app/index.html. Is there a way to redirect the page to app/home instead? Below is my app.js code: (function () { "use strict ...

`Save user edits on the webpage using Electron`

I am encountering an issue with my electron app. I use the window.loadUrl() method to navigate between pages. Some of these pages require users to input data that needs to be saved. The problem arises when a user enters information, moves to another page ...

Collapsing tabs feature in Bootstrap 4

I am working on a project with Bootstrap 4 Tab. My goal is to initially hide all tab contents and then show them when the corresponding tab is clicked. I achieved this by removing the active class from the tab-pane div. However, I encountered an issue wher ...

Encountered a problem while transitioning an asp.net 5 project to .net 6: "Issue with conflicting assets sharing the same target path."

After upgrading my ASP.NET 5 project to ASP.NET 6, I encountered an error upon building: https://i.sstatic.net/uyWfm.png The transition from ASP.NET 5 to ASP.NET 6 involved incorporating razor pages along with AngularJS typescript files in my project. ...

Implementing real-time time updates using php ajax technology

It's fascinating how websites can update the time dynamically without using ajax requests. I currently have a comment system in place. $('#comment').click(function(){ $.post(url,{ comment : $(this).siblings('textarea.#commen ...