Iterating through a JSON query in AngularJS using the ng-repeat directive

Using AngularJS in my current project has been a smooth experience so far. One thing I have noticed is that when I loop over employees in my view, I have to use the code

<li ng-repeat="employee in employees.employee">

instead of just

<li ng-repeat="employee in employees">

This got me wondering why I can't directly access the employees to iterate through the different JSON objects.

Here are snippets of the code from my project:

Controller

Test.controller('EmployeeListController', function($scope, Employee) {
    $scope.employees = Employee.query();
});

HTML View

<ul>
    <li ng-repeat="employee in employees.employee">
        <a href="mailto:{{employee.email}}" title="{{employee.email}}">{{employee.firstName}} {{employee.lastName}} ({{employee.email}})</a>
    </li>
</ul>

Factory

Test.factory('Employee', function ($resource) {
    return $resource('/TestServer/rest/employees/:employeeId', {}, {
        update: {method:'PUT'},
        query: {method:'GET', isArray:false}
    });
});

JSON Response

{"employee":[{"created":null,"description":"TestDescription","email":"TestMail","firstName":"TestFirstName","id":"1","image":"TestImage.jpg","lastModification":null,"lastName":"TestLastName","phone":"121212121212"},{"created":null,"description":"TestDescription","email":"TestEmail","firstName":"TestFirstName","id":"2","image":"TestImage2.jpg","lastModification":null,"lastName":"TestLastName","phone":"2124343434"}]}

Answer №1

The duplicator is echoing arrays repeatedly. Your reply contains an object instead. The array is located within the employee attribute in your JSON response, and this is indicated by isArray: false.

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

Encountering a node globby error when implementing multiple patterns

Currently, I am successfully using node glob for folder1 as shown below: glob('folder1/*.js'), function(err, files){ if (err) { console.log('Not able to get files from folder: ', err); } else { files.forEach(function (file) ...

How can I utilize a filter or pipe to populate product categories onto screens within Ionic 2?

I am considering creating an Ionic 2 app with 6 pages, but I'm unsure whether to utilize a Pipe or a Filter for the individual category pages and how to implement the necessary code. Each category page should be able to display products from the "app ...

Changing a string to uppercase and lowercase

I am currently working on a software that takes a string, divides it, capitalizes the first letter of the first string, and capitalizes all letters in the second string. Below is the code snippet: var fullName = "ThEoDORe RoOseVElT"; function nameEditor( ...

Troubleshooting: Node.js Express Server GET Handler Failing to Function

Recently, I've been attempting to build a GET request handler in Express.js. Here's the snippet of code I've put together: // include necessary files and packages const express = require('./data.json'); var app = express(); var m ...

Adjust the map automatically as the cursor approaches the map's edge in Google Maps API V3

My latest project involved creating a selection tool using the Rectangle shape tool. With this tool, users can easily select markers by drawing a rectangle over them and releasing their mouse to erase the selection (similar to selecting items on a desktop ...

Place a list with scrolling and overflow features side by side

Having trouble getting my headers to scroll with overflow auto and white-space nowrap. Can't figure out why it's not working. I want to create hyperlinks within headers to link to specific parts of the website. I have the code for hyperlinking s ...

Highcharts plots only appear once the browser window is adjusted

Having some issues while testing out the Highcharts javascript charting library on a specific page. The problem I'm encountering is that none of the data appears until I adjust the browser's size slightly. Prior to resizing, the tooltip does dis ...

angularJS equivalent of whenDOMReady

Greetings: Angular novice incoming. Behold, my code snippet residing in an angular.js territory: <div class="clearfix" ng-controller="Controller"> <h1>Active Ideas <button type="button" ng-click="search()">Fetch Ideas</bu ...

Encountering a problem while attempting to incorporate SQLite into a Node.js environment

I've encountered issues while attempting to import SQLite into node. Here is my import statement: import * as sqlite from './sqlite'; But unfortunately, I am receiving the following error message: node:internal/process/esm_loader:74 int ...

Why is a <script> tag placed within a <noscript> tag?

Lately, I've been exploring various websites with unique designs and content by inspecting their source code. One site that caught my attention was Squarespace, which had blocks of <script> tags within a <noscript> tag: <!-- Page is at ...

Is there a way to improve scrolling speed on Mobile Safari?

I'm currently working on a project utilizing angularjs and bootstrap, aiming to replicate iOS's navigationController feature. However, I'm encountering speed issues, particularly when scrolling between views on mobile safari iOS. The transi ...

Managing a prolonged press event in a React web application

Hello everyone! I am currently using React along with the Material UI library. I have a requirement to handle click events and long-press events separately. I suspect that the issue might be related to asynchronous state setting, but as of now, I am unsu ...

Manually controlling line breaks in HTML text

When collaborating with designers, they often have strong opinions about word wrapping in the final HTML page. If I am working on a fixed layout (non-responsive) and the designer is not satisfied with how the text wraps, there are several options available ...

Creating and fetching CSV files using PHP and AJAX

I have successfully created a PHP script that generates a CSV file for automatic download by the browser. The code below shows a working version with sample data for different car models. <?php $cars = array( array("Volvo",22,18), array("BMW",15,1 ...

Tips for retrieving the most recent UI updates after the container has been modified without the need to refresh the browser

Currently, I have developed a micro frontend application in Angular using module federation. This application is hosted in production with Docker containers. My main concern revolves around how to update the UI changes for the user without them needing to ...

Retrieve Static Property Values Using jQuery/JavaScript in Backend Code

My challenge is to fetch the Max value and Percent value into a jQuery function. I attempted to retrieve these values using hidden variables and Session variables on page load, but they always return 0. Here are the properties: public static int Max { ...

Is "Invalid Date" indicating an incorrect date?

Have you ever wondered why JavaScript returns 'Invalid Date' when setting an (invalid) date? It can be quite confusing and make it difficult to handle errors. So, what is the optimal way to deal with this issue? One approach is to check the date ...

`When trying to utilize $uibModal.open within karma (AngularJS Factory), an error is encountered as it

My current task involves testing a function that triggers the opening of a $uibmodal. Below is my factory function: confirmationMessage: function (message) { var modalInstance = $uibModal.open({ templateUrl: 'views/templates/utilsTemplates/ ...

Divide and conquer - meteorjs

I am currently utilizing the most recent version of Meteor. Meteor is designed to keep everything within the same directory structure, like this: MeteorProject -- .meteor -- client -- imports -- server -- test -- node_modules -- packa ...

What is the rationale behind not passing $scope to a service in AngularJS, and is it considered bad practice?

Is it advisable not to pass $scope to a service for certain reasons? I understand that services are intended to be reusable singletons, and passing a (potentially) large object to the service could lead to maintenance issues. However, assuming there is so ...