best practices for transferring object data to a table with ng-repeat

I have an object called 'SEG-Data with the following structure. I am attempting to display this data in a table using ng-repeat.

SEG_Data 
  Object {ImportValues: Array[2]}
     ImportValues: Array[2]
        0: Object
              ImportArray: "0045614"
              Name: "dean"
              Type: "xyz"
        1: Object
              ImportArray: "2567741"
              Name: "dean"
              Type: "abc"
        length: 2

The table setup is shown below, using ng-repeat with 'field in SEG_data.ImportValues' to access the values.... However, I'm not seeing the data displayed on the UI for some reason.

<table style="width:100%" border:"1px">
                <tr>
                    <th>ImportArray</th>
                    <th>Name</th>
                    <th>Type</th>
                </tr>
                <tr ng-repeat="field in SEG_Data.ImportValues">
                    <td>{{field.ImportArray}}</td>
                    <td>{{field.Name}}</td>
                    <td>{{field.Type}}</td>
                </tr>

            </table>

Do you have any insights as to why my display isn't working correctly?

Answer №1

The object in question is named SEG_Data, however, you are mentioning SEG_data with a lowercase 'd' in your template. Making this small correction will result in the data displaying properly.

Object

 $scope.SEG_Data = {
    ImportValues: [{
      ImportArray: "0045614",
      Name: "dean",
      Type: "xyz"
    }, {
      ImportArray: "2567741",
      Name: "dean",
      Type: "abc"
    }]
 };

Template

<table style="width:100%; border:1px">
    <tr>
        <th>ImportArray</th>
        <th>Name</th>
        <th>Type</th>
    </tr>
    <tr ng-repeat="field in SEG_Data.ImportValues">
        <td>{{field.ImportArray}}</td>
        <td>{{field.Name}}</td>
        <td>{{field.Type}}</td>
    </tr>
</table>

Check out the Plunker example

Answer №2

Here is a demonstration of the code in action:

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
     $scope.SEG_Data = {
    ImportValues: [{
      ImportArray: "0045614",
      Name: "dean",
      Type: "xyz"
    }, {
      ImportArray: "2567741",
      Name: "dean",
      Type: "abc"
    }]
 };
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
    <table>
        <tr>
            <th>ImportArray</th>
            <th>Name</th>
            <th>Type</th>
        </tr>
        <tr ng-repeat="field in SEG_Data.ImportValues">
            <td>{{field.ImportArray}}</td>
            <td>{{field.Name}}</td>
            <td>{{field.Type}}</td>
        </tr>
    </table>
</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

Assigning initial values in AngularJS for display prior to evaluation

My experience with using angularJs for basic functionality on an existing website was quite straightforward. It looked something like this: <div ng-app> <div ng-controller="TermsController"> <input type="checkbox" ng-model="ter ...

Dropdown with multiple selections organized in a hierarchical structure

I am in need of the following : Implement a drop-down menu that reflects hierarchical parent-child relationships. Include a checkbox for each node to allow for selection. If all child nodes are selected, their parent node should be automatically ch ...

Assigning a value to a variable from a method in Vue: a step-by-step guide

I'm having trouble assigning values from a method to variables in HTML. Here's what I have in my code: <b-card-text>X position {{xpos}}</b-card-text> <b-card-text>Y position {{ypos}}</b-card-text> I would like to assign v ...

Seeking animated SVGs using CSS styling

I've been trying to animate my SVG icon, but I seem to be missing something. I'm still fairly new to CSS animations. The issue I'm facing is that the position of the SVG isn't correct when the website loads. Additionally, during the an ...

Switching the URL without reloading the page in NEXT.JS

Currently, I am in the process of building an ecommerce store using NEXT.JS and Redux. Within the product listing page, I have incorporated a sorting select dropdown featuring options such as Price Low to High, Price High to Low, and New Arrivals. My goal ...

Utilizing Vue.js to add functionality for navigation buttons allowing users to move between survey questions

In my Vue.js component, I've written code to show survey questions in a mobile app for users. Here is a snippet of the code: <div class="col-12 p-0" v-for="( i, index ) in questions" :key="i"> <p cl ...

Use the ng-pattern regex to specifically identify instances where a pattern occurs only once

Looking for a string pattern 'abcd' followed by a colon(:) and any number of integers, with the restriction that this pattern cannot be repeated. Here are some examples of valid patterns: - abcd:23415 - abcd:23 And invalid patterns: - asda:4 ...

Uncovering complete hyperlink text using Scrapy

When using scrapy to extract data from a webpage, I encountered the following issue: <li> <a href="NEW-IMAGE?type=GENE&amp;object=EG10567"> <b> man </b> X - <i> Escherichia coli </i> </a> <br> </li> ...

Tips for preventing errors in formatting?

I created a field using rectangles as divs. However, when I add content to the rectangle divs, the formatting gets messed up. Can anyone help me fix this issue? Here's the link <div class='line' id='line1'> <div class=& ...

Is the xmlhttprequest timeout/abort feature not functioning as anticipated?

Check out this snippet of my AJAX function: /** * This function initiates an AJAX request * * @param url The URL to call (located in the /ajax/ directory) * @param data The data to send (will be serialized with JSON) * @param callback The fu ...

The Express GET route does not support parameters or additional paths

I am facing an issue with making a fetch request when trying to add additional path or parameters... Here is what I want to achieve: const fetchOwnerCardList = () => { fetch("http://localhost:5000/api/card/ownerCards", { method: "GET", header ...

Calculating the total price of items in a shopping cart by multiplying them with the quantity in Vue.js

I am currently working on enhancing the cart system in Vue.js, with a focus on displaying the total sum of product prices calculated by multiplying the price with the quantity. In my previous experience working with PHP, I achieved this calculation using ...

Handling AJAX requests using jQuery

I'm currently in the process of learning how to utilize jQuery Ajax. Could you explain to me the significance of function(response), as well as what exactly is meant by response == 1 and response == 2? jQuery.post(ajaxurl, data, function(response) { ...

removing the mapStateToProps function will result in an undefined value

I am new to React and I'm in the process of converting a class component to functional components using hooks. I need some guidance on safely removing 'mapStateToProps' without encountering undefined errors. I have two pages, A.js and B.js. ...

The forEach method in JavaScript seems to work asynchronously

After reviewing other discussions on this platform, it seems that the general agreement is that forEach should be synchronous and block. However, in my code, something appears to be off as it doesn't behave that way: var noDupes = false; // se ...

What's the secret behind generating a crisp 400 on paper?

Understanding Why it Prints 400 I'm struggling to comprehend the logic behind this var x = {}, y = { key: "y" }, z = { key: "z" }; x[y] = 100; x[z] = 200; console.log(x[y] + x[z]); ...

Client-side resizing an image before sending it to PHP for uploading

Greetings! Currently, I am utilizing a JavaScript library from this source to resize images on the client-side. The image resizing process works successfully with the following code: document.getElementById('foto_select').onchange = function( ...

What is the best way to vertically center elements within a navigation bar?

I'm currently working on a React application and I am trying to create a navigation bar. However, I am encountering some difficulties with aligning the elements in the middle of the nav bar layout. You can see the issue depicted in the image at this l ...

Ways to replace CSS classes created using makeStyles

To clarify, my development environment is using MUI version 4.12.3. Inside file A, I have a simplified code snippet for a functional component, along with the usage of makeStyles to style a JSX element within the return statement (not displayed here). Ever ...

An issue arose while trying to create the perfect seed with yeoman

While working on my first Yeoman webapp using the ultimate-seed-generator, I encountered some errors that are hindering progress: C:\Users\Fidel\Desktop\Nueva carpeta\new-proyect>npm install > <a href="/cdn-cgi/l/email ...