Converting the information retrieved from Firebase into a different format

My Project: In my Angular SPA, I am trying to retrieve data from Firebase and display specific values on the screen.

Approach Taken: The data returned from Firebase looks like this: Returned Data from Firebase

Error Encountered:

In order to display the data, I used an *NgFor loop in the HTML section of the component as shown below:

<div class="row">
  <ul class="list-group" *ngFor = "let guardian of guardians">
    <li class="list-group-item">{{ guardian.firstname }}</li>
  </ul>
</div>

ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed.

I have searched for solutions to resolve this error, and it is suggested to transform the received data into an array. Despite my attempt to do so with the following code:

    for (const guardian in data) {array.push(guardian);}

The resulting array is missing all the values I need. It appears in this format:

["-L3n95t-rxA4-bOgc8fz", "-L3nF0h5EEKtwAiZv0Q7",
 "-L3oWoBmoXK3-5XBkx9i", "-L3oWxEhAcUGQX2P4yES", "-L41_cK3KD6DMduhG3P3", 
"-L4CbTtNqGuVyT3hzY-R", "-L4CfKsBxfQxSKd2PR4s", "-L4EDFkbsWMrT61fLjhD"]

Although this allows me to use the *NgFor statement, the transformed data is not useful to me at this point. Any insights on how I can properly manipulate this data?

After struggling with this issue for three days, any assistance or guidance would be greatly appreciated! :)

Answer №1

The information stored in the array consists of each key found in the guardians object. The goal now is to make use of these keys. Let's say you have assigned a value to your key array like this.guardianKeys = array

Afterwards, you can cycle through the keys and retrieve the original guardians objects as follows:


<div class="row">
  <ul class="list-group" *ngFor = "let key of guardianKeys">
    <li class="list-group-item">{{ guardians[key].City }}</li>
    <li class="list-group-item">{{ guardians[key].Phone }}</li>
    <li class="list-group-item">{{ guardians[key].State }}</li>
    ...
  </ul>
</div>

Answer №2

The issue was successfully resolved using this method.

for (const person in information) {list.push(information[person]);}

By populating an empty list with the data, I could then easily loop through it using *NgFor directive.

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

Charts created using Google VisualizationORThe visual representations

My chart is currently not displaying at 100% width as I intended. I would like the chart to span from the beginning to the end of the container. https://i.stack.imgur.com/Xjw6g.png Here's my code snippet: test.controller('testCtrl', [&apo ...

Utilizing client extension for Postgres with Prisma to activate RLS: A step-by-step guide

Recently, I attempted to implement client extension as advised on Github. My approach involved defining row level security policies in my migration.sql file: -- Enabling Row Level Security ALTER TABLE "User" ENABLE ROW LEVEL SECURITY; ALTER TABLE ...

Determine the number of properties present in two arrays by comparing them

Looking to compare two arrays and determine the count of items in the master list. A sample master list could be: { name: 'Emily', age: 29 }, { name: 'Jack', age: 31 }, { name: 'Lily', age: 28 }, { name: 'Emily', a ...

Utilize Ionic to apply filters based on multiple conditions simultaneously

I wish to sort through various statuses. The JSON data I have is as follows: [{name:'firstPerson',status:1},{name:'secondPerson',status:2},{name:'thirdPerson',status:3}] Here's how I iterate over them: <div class=" ...

Filtering input for multiple header columns in an Angular table

A complex Angular table structure has been implemented with three columns. Each column header contains an input field for Stock Number, Case, and Availability. Users have the flexibility to search using a Single Input (Stock Number OR Case OR Availability ...

Encountering the "Argument of type 'string' is not assignable to parameter of type 'never'" error when using Array.prototype.includes

The data type for keys is a combination of string[] | number[], which is derived from the ID type. The data type for id is simply ID. We want to check if the id exists within the array of keys. import React, { useState } from 'react'; type Distr ...

Finding it challenging to adapt an AngularJs component-based modal to TypeScript

When creating an AngularJS component in JavaScript and displaying it as a modal using ui-bootstrap, you need to pass bindings that the modal instance can use for dismissing or closing itself: app.component("fringeEdit", { controller: "FringeEditCont ...

Angular: the xhrRequest is failing to be sent

I am facing an issue with a service function that handles an HTTP post request. The request does not get sent for some reason. However, when I add a subscription to the post method, the request is successfully executed. In other services that have the sam ...

What sets 'babel-plugin-module-resolver' apart from 'tsconfig-paths'?

After coming across a SSR demo (React+typescript+Next.js) that utilizes two plugins, I found myself wondering why exactly it needs both of them. In my opinion, these two plugins seem to serve the same purpose. Can anyone provide insight as to why this is? ...

Dropdown element vanishes upon selecting in HTML

Utilizing Angular's ng-init to populate a rest call function and populate $scope.races before filling up the dropdown. Initially, everything appears to be working correctly. However, upon selecting an option from the dropdown menu, it immediately cle ...

Despite setting the esModuleInterop flag, I am still encountering an error with default imports

My React project with TypeScript is causing some issues. In the main tsx file, the import React from 'react' line works fine. However, in my test file, I keep getting the TS1259 error. I suspect there might be a problem with my TS/Jest/Babel conf ...

Achieving successful CSRF integration with Express.js, AngularJS, and Ngin

Having difficulty understanding how to set up csrf protection in my specific setup. My configuration includes nginx for serving static files, expressjs for handling API calls, and angularjs for the front end. All requests to /api/* are routed to express, w ...

How can one determine if a background image has successfully loaded in an Angular application?

In my Angular 7 application, I am displaying a background image in a div. However, there are instances when the link to the image is broken. The way I bind the image in my HTML is as follows: <div [ngStyle]="{'background-image': 'url(&a ...

Can you explain the distinction between using get() and valueChanges() in an Angular Firestore query?

Can someone help clarify the distinction between get() and valueChanges() when executing a query in Angular Firestore? Are there specific advantages or disadvantages to consider, such as differences in reads or costs? ...

Deactivate the chosen tab by clicking the Mat-Tab button

I was trying to implement a way to disable the selected mat-tab and its elements when a button is clicked, //HTML <mat-tab-group #tabGroup> <mat-tab *ngFor="let subject of subjects" [label]="subject.name"> {{ subject.name }} ...

Unexpected error encountered in Angular 2 beta: IE 10 displays 'Potentially unhandled rejection [3] SyntaxError: Expected'

Question regarding Angular 2 Beta: I am starting off with a general overview in the hopes that this issue is already recognized, and I simply overlooked something during my research. Initially, when Angular 2 Beta.0 was released, I managed to run a basic m ...

Slider with a progress bar

Have you ever wondered if it's possible to create a progress bar using an input range? Imagine someone entering a number and the bar moves to the right, changing its background color on the left side of the thumb based on the size of the number. Check ...

The error message "SyntaxError: Cannot use import statement outside a module" popped up while working with discord.js, typescript, heroku

// Necessary imports for running the discord bot smoothly import DiscordJS, { TextChannel, Intents, Message, Channel, NewsChannel, ThreadChannel, DiscordAPIError } from 'discord.js' type guildTextBasedChannel = TextChannel | NewsChannel | ThreadC ...

Understanding how to effectively conduct unit tests on the 'resolve' property within an Angular-UI Bootstrap Modal component is essential for ensuring the functionality and

I'm currently working on building a unit test that verifies the correct variable is being passed to the resolve property within the ui.bootstrap.modal from Angular-UI Bootstrap components. Here's my progress so far: // Controller angular.module( ...

Having trouble with Angular UI Select functionality?

I have integrated the angular ui select library from https://github.com/angular-ui/ui-select into my project. Instead of using the traditional select element, I am now utilizing the ui-select directive. This is a snippet of my code: <select class=" ...