When using ng-repeat in Angular JS, only the first element will be displayed on the

I am currently utilizing Angular 1.5.5

function RetrieveDashboardDataForAllEmployees()
{
    var response = eRotaService.RetrieveDashboard();
    response.then(function (data) {
        $scope.weekDays = data.data;
        console.log(data.data);

    }, function () {
        alert("Failed to load the dashboard.");

    })
}

The .NET service provides JSON data :

{
    "weekDays": [{
        "name": "Monday",
        "display": 0,
        "employees": [{
            "employeeId": 1,
            "name": "Adam",
            "start": 8,
            "finish": 16,
            "gridSetup": {
            "sizeX": 8,
            "sizeY": 1,
            "row": 0,
            "col": 8
        }
    }, {
        "employeeId": 2,
        "name": "Paul",
        "start": 16,
        "finish": 22,
        "gridSetup": {
            "sizeX": 6,
            "sizeY": 1,
            "row": 0,
            "col": 16
        }
    }]
}, {
    "name": "Tuesday",
    "display": 1,
    "employees": [{
        "employeeId": 1,
        "name": "Bob",
        "start": 10,
        "finish": 18,
        "gridSetup": {
            "sizeX": 8,
            "sizeY": 1,
            "row": 0,
            "col": 10
        }
    }, {
        "employeeId": 2,
        "name": "Paul",
        "start": 16,
        "finish": 22,
        "gridSetup": {
            "sizeX": 6,
            "sizeY": 1,
            "row": 0,
            "col": 16
                }
            }]
        }]
    

I intend to showcase each day of the week, starting with Monday as the first day.

<div class="row" ng-repeat="week in weekDays">

    @for (int i = -2; i < 22; i+=2 )
    {
        <div class="col-sm-1">
            @string.Format("{0}:00", i + 2)
        </div>
    }
    <hr />
    <div class="col-sm-12">
        <h3>{{week[$index].name}}</h3>
        <hr />
        <div class="row" ng-repeat="employee in week[$index].employees">
            <div class="col-sm-12">
                <h4>{{employee.name}}</h4>
                <hr />

                <div gridster>
                    <ul>
                        <li gridster-item="employee.gridSetup"  ng-cloak>
                            <div class="panel-default" >
                                <div class="panel-heading">
                                    <h5>From : {{employee.start}} to {{employee.finish}}</h5> 
                                </div>

                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

</div>

When attempting to use ng-repeat without $index, the result displayed a blank page with no errors related to Angular JS.

Answer №1

<div class="row" ng-repeat="week in weekDays">

Perhaps it should actually be

<div class="row" ng-repeat="week in weekDays.weekDays">

The JSON String is somewhat formatted like this:

{
"weekDays": [
    {
        "name": "Monday",
        "display": 0,
        "employees": [
            {
                "employeeId": 1,
                "name": "Adam",
                "start": 8,
                "finish": 16,
                "gridSetup": {
                    "sizeX": 8,
                    "sizeY": 1,
                    "row": 0,
                    "col": 8
                }
            },
            {
                "employeeId": 2,
                "name": "Paul",
                "start": 16,
                "finish": 22,
                "gridSetup": {
                    "sizeX": 6,
                    "sizeY": 1,
                    "row": 0,
                    "col": 16
                }
            }
        ]
    },
    {
        "name": "Tuesday",
        "display": 1,
        "employees": [
            {
                "employeeId": 1,
                "name": "Bob",
                "start": 10,
                "finish": 18,
                "gridSetup": {
                    "sizeX": 8,
                    "sizeY": 1,
                    "row": 0,
                    "col": 10
                }
            },
            {
                "employeeId": 2,
                "name": "Paul",
                "start": 16,
                "finish": 22,
                "gridSetup": {
                    "sizeX": 6,
                    "sizeY": 1,
                    "row": 0,
                    "col": 16
                }
            }
        ]
    }
]
}

This means that all weekdays are within the "weekDays" element. In 'week' you have only one week and do not need an array indexer to access the entire thing.

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

Breaking down an HTTP request using the Angular, Express, and MongoDB stack

In order to optimize performance, I am faced with the challenge of retrieving a large number of elements from a MongoDB database and displaying them on the front-end. Fetching all elements in a single request may negatively impact performance due to the la ...

Encountered an InvalidCastException while attempting to switch from type 'Npgsql.PoolingDataSource' to type 'Npgsql.MultiplexingDataSource' during a Postgres call

While working with Postgres, I encountered a strange issue that only occurred once despite making thousands of calls per day. Here is the code snippet that caused the problem: using Npgsql; ///class, constructor, all the definitions here NpgsqlConnection _ ...

What is the optimal strategy for managing multilingual text in a React website?

As I develop a react website with multiple localizations, I am faced with the question of how to best store UI texts for different languages. Currently, I am contemplating two approaches: One option is to store text directly in the UI code, using an objec ...

Script for Grunt build that analyzes an XML document to identify the files that need to be duplicated

copy: { build: { cwd: 'app', src: ['**', '!**/vendors/**', '!**src/js/*.js',], dest: 'dist', expand: true } } When utilizing Grunt build scripts to create a distribution folder for the ...

Enhance your Next.js (React) Component by implementing a feature that filters table results without causing unnecessary re

I am currently working on a Next.js client component that displays a data table with a search bar for filtering. The main issue I'm facing is that when I type in the search bar, the entire component re-renders, causing the search to lose focus and int ...

How to customize the font size in three.js CSS3DRenderer

I am trying to use threejs's CSS3DRenderer to display text in my 3D view. However, I am facing issues with controlling the font size. Despite setting font-size: 1px in CSS, the text remains large. I also attempted to adjust the scale of the css3dobjec ...

Refreshing a UserControl in a Windows Forms application using C# and the .NET Framework

I am developing a Windows Forms application in C# that includes multiple UserControls. Within UserControl1, I dynamically create panels that each contain various elements such as checkboxes, labels, listboxes, picture boxes, and comboboxes. The values wit ...

Retrieve the text input from its respective radio button

There are two radio buttons, each accompanied by an input text field. When a user selects a radio button, they can also enter some corresponding text. My inquiry is: What is the best method to retrieve the entered text for the selected radio button? ...

Unable to retrieve the information through the use of the openWeatherMap API in JavaScript

Having trouble pinpointing the issue as nothing is being displayed in the selected div. $(document).ready(function(){ var lat, lng, data; // Retrieve current location if (navigator.geolocation) { navigator.geolocation.getCurrentPositio ...

Express 4 app.use not functioning properly

My backend setup is fairly straightforward with a few routes. I prefer to keep the route logic separate from the server.js file, but for some reason, when I make a POST request to the route, it returns a 404 error. In the server.js file: // Import necess ...

Steps to isolate the "changed" values from two JSON objects

Here is a unique question that involves comparing JSON structures and extracting the differences. A JqTree has been created, where when the user changes its tree structure, both the "old" JSON and "new" JSON structures need to be compared. Only the values ...

What is the best way to access the localized strings for Day, Week, Month, and Year in .Net?

Is there a way in .NET to obtain the localized translations for words like "Day", "Week", "Month", and "Year"? I am already familiar with using DateTimeFormatInfo.CurrentInfo.GetMonthName and GetDayName to retrieve names of calendar parts such as June, F ...

The dynamic component remains unresponsive when prompted

When I try to add an item as a submenu in my menu by clicking a button, the jQuery code for the parent items does not function as expected. $('.menu li.has-sub>a').on('click', function() { alert("Working"); }); $(".test").click ...

Struggling to Align NAV buttons to the Right in React Framework

My current Mobile Header view can be seen here: https://i.stack.imgur.com/CcspN.png I am looking to achieve a layout similar to this, https://i.stack.imgur.com/pH15p.png. So far, I have only been able to accomplish this by setting specific left margins, ...

Does ng-include fetch the included HTML files individually or merge them into a single HTML file before serving?

Is there a performance impact when using the ng-include Angular directive, in terms of having included HTML files downloaded as separate entities to the user's browsers? I am utilizing a CDN like AWS CloudFront instead of a node server to serve the H ...

Identifying the camera model using getMediaStream

Are there methods available to determine if a user's device has a front, rear, or dual cameras installed? For instance, laptops typically only have a front-facing camera while some devices may have both. I am looking for a way to identify the type of ...

Avoiding conflicts among jquery prototype/plugin methods

Imagine I have a primary JavaScript file on my website that includes the following code: $.fn.extend({ break: function(){ // Add your custom code here }, cut: function(){ // More code here }, // ...and many other methods }); When using t ...

Manipulating vertices in Three.js

I am fairly new to Three.js and I am attempting to create a basic PlaneGeometry. The process would involve: The user will specify their preferred height and width for the PlaneGeometry The browser will then render the plane with the height and width ...

Is there a way to choose the final JSON element using Javascript or Google Apps Script?

Imagine if I extracted this data from a constantly updating JSON file. [{ "data": { "member": "Feufoe, Robert", "project": "Random Event", }, "folder": null, "id": 1062110, "spam": null }, { "data": { "membe ...

Does .NET 8 support backward compatibility with .NET 7?

At my workplace, we received notice that support for .NET 7 will be ending at the end of the month, so the runtimes on our servers will be uninstalled. Instead, they will be installing the latest .NET 8 hosting bundle. All of our applications currently ru ...