Adjust the Index value within an angularJS application

I have a task of displaying JSON data in tabular form. The JSON consists of various arrays that I need to loop through separately. Everything is functioning correctly except for the $index value.

View Working Plunkr

Currently, I am looping through each array in separate rows. However, I am looking for a solution to update the index values sequentially (1, 2, 3...). Any suggestions?

Answer №1

If you absolutely must iterate through them as separate arrays, you will need to combine the total number of elements in the first array with the indexes for the second array, like so:

<!-- secondary tbody: -->
<tbody>
  <tr ng-repeat="prioritymembers in Records.priorityMembers">
    <td class="number" ng-bind="Records.stdMembers.length + $index+1"></td>
    <td class="name" ng-bind="prioritymembers.members.fname"></td>
  </tr>
</tbody>

Check out this live example here: http://plnkr.co/edit/1HiGoMuFAOTyOpD3SLoX?p=preview

Answer №2

This problem is quite intriguing, and I believe finding a straightforward solution may be challenging.

One potential approach could be:

<div ng-repeat="member in combinedMembersArray">
    <p>{{$index + 1}}. {{member.name}}</p>
</div>

An alternative and more organized solution might involve consolidating the data into a single array within the controller and iterating over that unified dataset rather than managing two separate iterations within different bodies.

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

Utilizing ARC4 Encryption with Javascript on iOS devices

I keep getting a blank result when running this code. It doesn't display anything. [self.webview loadHTMLString:@"<script src=\"http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/rc4.js\"></script>" bas ...

Changing a C# Datetime type to a Date using javascript in an ASP.NET MVC Razor web application

Having trouble converting dates in JavaScript? Check out this code snippet: $(document).ready(function () { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); ...

What is the best way to access a nested array within a React component?

Here is an example of the array data: { "firstname": "Jessica", "lastname": "Wood", "favorite": { "movie": Flint Town, "drink": Sprite } } When attempting to access the "drink" property, I encountered an error stating "Objects are ...

Customizing pressed row styles and properties within a map iteration in React Native

How can I modify the style of a single item in a list when a button is pressed in React-Native? I want only the pressed item to change, not the entire row. Here is my attempt at implementing this: //hooks const [activeStyle, setActiveStyle] = useState( ...

unable to add browse-sync to Ubuntu 16.04

I recently installed nodejs and npm and attempted to install browser-sync using the command npm install -g browser-sync. However, I encountered an error. npm install -g browser-sync npm ERR! Linux 4.15.0-101-generic npm ERR! argv "/usr/bin/nodejs" "/ ...

Displaying an array value instead of a new value list in a React component

Situation - Initial number input in text field - 1 List of Items - 1 6 11 Upon removing 1 from the text field, the list becomes - New List Items - NaN NaN NaN Now, if you input 4 in the field. The updated List Items are - NaN NaN 4 9 14 Expected ...

Encountering issues with the display of JSON data in MVC

Question: How can I pass JSON data from my controller to the view and render it using JavaScript? [HttpGet] [AllowAnonymous] public ActionResult Index() { ServiceReference1.ipostep_vP001sap0003in_WCSX_comsapb1ivplatformruntime_INB_WS_C ...

Experiencing difficulty in successfully updating a React child component when the prop passed from the parent component is

In the backend implementation, I have successfully set up a socket.io, Node, Express configuration that has been tested to work correctly. It is emitting the right number of broadcasts to the appropriate client using socket.emit("team_set", gameI ...

Utilizing Node modules like Sentry in HTML template files when served from Golang using the gin-gonic package

Summary: I am trying to integrate Sentry into a Golang application that renders a simple HTML page using the gin-gonic package. Including vanilla Javascript works fine, but I am facing difficulties when trying to include scripts with dependencies. I have ...

Styling the active selection in nav class with bold attribute in Bootstrap/AngularJs

How can I apply the bold attribute to the currently selected nav bar item? <ul class="nav"> <li role="presentation" ng-repeate="item in items" ng-class="{'active':navLink == item.header}"> </li> &l ...

The functionality of AJAX is hindered in the browser when attempting to fetch data from a URL

Lately, I've been encountering a strange issue when trying to fetch data from a URL. $.ajax({ url: 'URLHERE', dataType: 'html', success: function(data) { //function 2 var xml = $.parseXML(data) $(xml).find('StopLoca ...

Utilize JavaScript to append a CSS class to a dynamic unordered list item anchor element

I am working with a list of ul li in a div where I need to dynamically add CSS classes based on the click event of an anchor tag. Below is the HTML structure of the ul li elements: <div class="tabs1"> <ul> <li class="active"> ...

News ticker plugin for jQuery, subtly nestled amongst various other jQuery plugins and captivating images

I am having trouble replicating this issue on a fiddle. Here's a link to the website (which will always be available). Upon visiting the site, you will notice a news ticker at the bottom. However, as you scroll down and pass 1. Main Slider, 2. Announ ...

Incorporating props into every page through getInitialProps in Next.js

I am trying to ensure that the same props are loaded on all pages I navigate to. My approach involves using _app.js as shown below: export default function MyApp({ Component, pageProps }) { return <Component {...pageProps} /> } MyApp.getInit ...

Stopping the ability to navigate within an Ionic application

I am attempting to block navigation and display a popup in a controller. $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { if(someConditionMet) { event.preventDefault(); showPopup(); } } ...

Simulate a service during an end-to-end test using Protractor

When writing a functional test for my app, I am seeking a way to mock my loginService service in order to speed up the testing process. Specifically, I do not wish to mock the $http service, but rather the service that interacts with it internally. However ...

Mapping routes in ExpressJS

I am interested in developing a programmatic route generator. Within my project, I have a module called ./utils/crud.js structured as follows: const express = require('express'); const router = express.Router(); module.exports = function (Mode ...

Reduce the length of the text and display it upon hovering with the mouse

I am trying to figure out how to truncate text and have it expand on mouseover in a paragraph element. I attempted to truncate the content using a specific code, but I encountered an issue. While my current code expands the content when clicking on the el ...

Using the Context API dispatch (consumer) within the _app.js class component in Next.js

How can I access the dispatch Context API methods in the _app.js file? The issue I am facing is that I am using React hooks along with Context API, and as _app.js is a Class component, I cannot directly use hooks within it. Below is my current code snipp ...

Is it possible to utilize window.location.replace function within an iframe?

Is it possible to use window.location.replace to bypass history and target on-page anchors without page reloads, but encounter issues when working within iframes? The main problem seems to be a CSP (content security policy) violation for script-src ' ...