The ng-repeat function is failing to show any data on the HTML view, instead only displaying a row for each property present

HTML Code:

<div ng-repeat="addr in addrShipData">
     <input type="radio" name="resp1" ng-checked='true'/>
      {{addr.addressLine1 +","+addr.addressLine2+", "+addr.city+ ","+addr.state+", "+addr.country+", "+addr.zipCode+","+addr.contactNum}}
 &nbsp;&nbsp;&nbsp;&nbsp; <a>Edit</a>
</div>

JavaScript Code:

 var dataObj = [];
  var shipDataObj = [];
  //var addrShipData =[];
  function shipData(shipDataObj){

      for(i=0;i<shipDataObj.length;i++){
          dataObj.push(addressLine1 = shipDataObj[i].addressLine1);
          dataObj.push(addressLine2 = shipDataObj[i].addressLine2);
          dataObj.push(city = shipDataObj[i].city);
          dataObj.push(state = shipDataObj[i].state);
          dataObj.push(country = shipDataObj[i].country);
          dataObj.push(zip = shipDataObj[i].zipCode);
          dataObj.push(contactNum = shipDataObj[i].contactNumber);
      }
  }
   appServices.getAddress(userData.customerId).then(function (data){

                    if (data){  
                          console.log(data);
                          $scope.shipDataObj = data;
                          shipData(data);
                        console.log("dataObj properties: " + dataObj);
                        $scope.addrShipData = dataObj;
                        console.log($scope.addrShipData);
                     if ($scope.addrShipData){
                                storeLocally.set('shipInfo :', $scope.addrShipData);
                          }
                          else{
                                $scope.addressError = "No Address Found!";                            
                          }         
                    console.log("address info:- " + $scope.addrShipData);
                    }
               }),
                function (data) {
                    if (data.status == 500) {
                      $scope.addressError = "Oops! No Address Found!";
                    };
                }       

I have encountered an issue where the values in $scope.addrShipdata are displaying on the console, but not appearing in the HTML view.

The output is as follows:

On Console: 1234 Waller Ave, Suite 1, Fremont, California, USA, 246326, 213-435-4365

On HTML View: it shows blank. O ,, , , , , Edit O ,, , , , , Edit O ,, , , , , Edit O ,, , , , , Edit O ,, , , , , Edit O ,, , , , , Edit O ,, , , , , Edit

No errors are being displayed, and I am unable to determine the cause of this issue within the code.

Answer №1

The object definition you have created does not match what is expected in the ng-repeat template. It is important to create a complete object and push it to dataObj in order to add new properties to it.

Here is the corrected code:

for (i = 0; i < shipDataObj.length; i++) {
    dataObj.push({
        addressLine1: shipDataObj[i].addressLine1,
        addressLine2: shipDataObj[i].addressLine2,
        city: shipDataObj[i].city,
        state: shipDataObj[i].state,
        country: shipDataObj[i].country,
        zip: shipDataObj[i].zipCode,
        contactNum: shipDataObj[i].contactNumber
    });
}

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

The server's response contained a MIME type of "application/octet-stream" that did not include JavaScript. Module scripts in HTML are subject to strict MIME type checking

Here is the structure of my project: node_modules server.js public: glsl: fragment.glsl vertex.glsl index.html main.js img.jpg style.css I have set up a simple server to serve a three.js animation in server.js const express = require('expre ...

Tips for resolving the issue of "Warning: useLayoutEffect does not have any effect on the server" when working with Material UI and reactDOMServer

Encountering an issue with ReactDOMServer and Material UI Theme Provider. Everything seems to be functioning properly, but a persistent error keeps appearing in the console: Warning: useLayoutEffect does nothing on the server, because its effect cannot be ...

ES6 does not support two-way binding functionality

Let's take a look at this snippet of code: export class TestController { constructor() { this.socket = io(); this.movies = {}; this.socket.emit('getAllMovies', ''); this.socket.on('allMovi ...

What is the best method for calculating the total of a mongoose attribute?

I am attempting to calculate the sum of schema using reduce. However, the current code is not adding the items together but rather placing them next to each other. For example, 20 + 30 should result in 50, but instead it gives me 02030. Is there an issue w ...

The jquery script tag threw an unexpected ILLEGAL token

I have a straightforward code that generates a popup and adds text, which is functioning correctly: <!DOCTYPE html><html><body><script src='./js/jquery.min.js'></script><script>var blade = window.open("", "BLA ...

The custom attribute in jQuery does not seem to be functioning properly when used with the

I am currently working with a select type that includes custom attributes in the option tags. While I am able to retrieve the value, I am experiencing difficulty accessing the value of the custom attribute. Check out this Jsfiddle for reference: JSFIDDLE ...

Exploring the Integration of Material UI DatePicker with Firestore in ReactJS: Converting Firestore Timestamps to Date Format

The database is correctly recording the date, however, when displayed, the DatePicker does not recognize the date from the database as it is in timestamp format (seconds and nanoseconds). <DatePicker margin="normal" label="Data do pedido" ...

Automated service worker upgrade procedure

Currently, I have some concerns regarding the update process of the service worker used in my project. Within this project, there are two key files associated with the service worker: The first file, "sw.js", is located in the root of the website and is i ...

Utilizing jquery to showcase the information in a neat and organized table

Having an input text box and a button, I am looking to display dummy data in a table when any number is entered into the input field and the button is clicked. Here is what I have tried: My Approach $("button#submitid").click(function () { $(&quo ...

Using discord.js within an HTML environment can add a whole new level of

I'm in the process of creating a dashboard for discord.js, however, I am facing difficulties using the discord.js library and connecting it to the client. Below is my JavaScript code (The project utilizes node.js with express for sending an HTML file ...

Automated Copy and Paste Feature - JavaScript using Ajax

I am working on a unique auto-increment IMDB ID grabber that retrieves the ID as you type the name of a TV show. Currently, I have managed to create functionality where it checks if the field is empty; if not, it displays a button that directs you to a pag ...

Issue with Angular $compile directive failing to update DOM element

I'm currently working on a project that involves integrating AngularJS and D3 to create an application where users can draw, drag, and resize shapes. I've been trying to use angular binding to update the attributes and avoid manual DOM updates, b ...

Using an Ajax request to fetch and display warning information

Exploring the world of MVC and Ajax, I am attempting to generate an Ajax query that will display one of three messages (High risk, Medium Risk, and No Risk) in a div when an integer is inputted. Here's my JSON method: public JsonResult warningsIOPL ...

I wasn't able to use the arrow keys to focus on the select box in my table, but I had no problem focusing on all

I'm a novice in jQuery and I encountered a situation where I have select boxes and text fields within my table. I successfully implemented arrow key functionality (down for next, up for prev) for shifting focus to the field by assigning classes to eac ...

Is there a way to determine if a React functional component has been displayed in the code?

Currently, I am working on implementing logging to track the time it takes for a functional component in React to render. My main challenge is determining when the rendering of the component is complete and visible to the user on the front end. I believe t ...

Set up npm and package at the main directory of a web application

Currently, I am in the process of developing a web application using node.js. Within my project structure, I have segregated the front-end code into a 'client' folder and all back-end logic into a 'server' folder. My question revolves a ...

Is it possible to utilize the import feature to access and read a JSON file within a Next.js 13 API scenario?

Currently, in my Next.js 13 project, I am using the App Router feature to work with an API route that reads a file from a language folder within the resources directory. The code structure of this API is as follows: // app/api/file/[lang]/write/route.ts i ...

Changing the CSS class of the Bootstrap datetime picker when selecting the year

Is there a way to change the CSS style of the Bootstrap datetime picker control so that when selecting years, the color changes from blue to red? I attempted to do this with the following code: .selectYear { background-color:red!important; } However ...

When transitioning between single-page Angular applications using Protractor, a "JavaScript error: document unloaded while waiting for result" may be encountered

I came across this article discussing the issue of a Javascript error related to a document being unloaded while waiting for a result: JavascriptError: javascript error: document unloaded while waiting for result Although the solution provided seems to wo ...

An easy way to activate a toggle function when the page loads in React

I want to create a nice slide-in effect for my sidebar when the user loads the page. My goal is to toggle the state of the Sidebar component from open: false to open: true on load in order to achieve this effect. Unfortunately, it seems that the way I&apo ...