"Utilizing the ngFor directive in Angular 4 to iterate through parent keys and

I am striving to gather all the values from the UserHardware along with their respective parent keys. The child nodes housed within the randomly generated keys are structured as: name: Test, desc: test

https://i.sstatic.net/TypzB.png

Below is my code snippet in the constructor(Component)

this.userHardwareList = db.list('UserHardware/');
this.items = this.userHardwareList.snapshotChanges().map(changes => {
  return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});

In the (template)

<li *ngFor="let item of items | async">
 {{item.key}}
</li>

Currently, I am only able to retrieve the value udwcGxqx50ZtoF8EABoFh8GVet2 (UID). However, I also wish to access the values nested within this UID.

After attempting: {{item.name}} I notice that nothing gets displayed.

Interestingly, when I modify the code in the constructor like so:

this.userHardwareList = db.list('UserHardware/udwcGxqx50ZtoF8EABoFh8GVet2');

Everything works flawlessly, allowing me to access values and unique generated keys using

{{item.name}}` {{item.key}}` {{item.desc}}`

The question now arises, how can I achieve the same functionality without specifying the UID?

Answer №1

It seems like you are looking to achieve the following:

const userHardwareList = db.list('UserHardware/');
this.items = this.userHardwareList.snapshotChanges().map(changes => {
  return changes.map(c => ({ key: c.payload.key, data:c.payload.val() }));
});

and then,

<ul *ngFor="let item of items | async">
 {{item.key}}
  <ol>
    <li *ngFor="let data of items">
      {{data.name}}{{data.description}}
    </li>
  <ol>
</ul>

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

Obtain access to the DOM element using template reference variables within the component

Searching for a method to obtain a reference to the DOM element for an Angular 2 component through a template reference variable? The behavior differs when working with standard HTML tags versus components. For example: <!--var1 refers to the DOM node ...

Unable to associate with 'ngForOf' as it is not recognized as a valid property in Angular 5

As a newcomer to angular, I recently created a small application. However, I encountered an issue where the directives *ngIf, *ngFor, and nfForm are not functioning properly (I suspect an error in CommonModule). Here is a snippet from my file.html: <d ...

Ensure that the function parameter only accepts keys that are present in the specified object

I have an object with specific types for its values: type Type = { [key: string]: ValueType } const variable: Type = { key1: valueType, key2: valueType, key3: valueType, } Now, I need a function called func that should only accept keys from v ...

The struggle continues in attempting to adjust Angular Material 2 dialog positioning using MdDialogConfig

Does anyone know how to adjust the position of an MdDialog? openDialog() { let config = new MdDialogConfig(); config.height = '15px'; config.position.left = '5px'; let dialogRef = this.dialog.open(BasicAlertDialog, config); dialogRef. ...

The FullCalendar does not appear as expected on Angular version 16

https://i.stack.imgur.com/DTAKr.pngI followed the steps to install FullCalendar in my Ionic 6 Angular 16 app as outlined on https://fullcalendar.io/docs/angular. However, nothing is showing up in the browser (chrome). The Inspector tool shows that the Ful ...

Bootstrap Modal Fails to Display Image Within Its Container

I'm currently working on my e-commerce website, where I'm attempting to implement a feature that allows users to view product images in a modal for a closer look. The product page contains a list of images, and when a user clicks on one, it shoul ...

Custom hooks for Typescript and Javascript

As a beginner, I am currently working on refactoring JavaScript hooks into TypeScript. However, I am facing an issue where I cannot get the button onClick event to change state. Can anyone provide assistance with this? Here is the useToggler component: i ...

Creating Elements with Angular 2

How can I use the document.createelement statement in TypeScript? I have been trying to solve this issue but haven't found a solution yet. Is there a way to create this function? Below is the component: import {Component,ViewChild, ElementRef} from ...

Inquired about the installation of Typescript in the Docker image building process despite it already being installed

I am in the process of creating a docker image for a Next.js/React application that utilizes Typescript. Typescript is installed and I can successfully generate a local build without docker. However, during the docker image creation, I encounter the foll ...

Extracting the base href in Angular 6

Is there a way to dynamically retrieve /CTX-ROOT/assets/tiny-editor/langs/cs.js in Angular 6 component without using the PlatformLocation#getBaseHrefFromDOM method? constructor( private zone: NgZone, private platformLocation: PlatformLocation) ...

Angular is intercepting HTTP subscriptions without finalizing them

Within my code, I have a system in place where an interceptor is triggered to check for HTTP responses with the status code 401. If this code is detected, it initiates a request for a refresh-token by calling the method refreshToken(), before retrying the ...

Having trouble with the post request to upload files to an S3 pre-signed URL, but strangely the put request is successful when using the

I am looking to upload files to S3 using pre-signed URLs generated from my backend application. On the front end, I am utilizing angular HttpClient v8.2.9 for sending put requests, which is working fine with the following code snippet: const formData = ne ...

When accessing a page protected by Angular AuthGuard, users may be redirected but could experience the issue of the page

The Routes are structured as follows: const routes: Routes = [ { path: '', component: NewsfeedComponent, children: [ { path: ':id/edit', component: NewsfeedEditComponent, canActivate: [AdminG ...

OAuth does not support this response type

Hi there, I'm currently working on a web application using Angular 2. The back end has oauth authentication through webapi. In the front end, I am utilizing Angular 2. When attempting to log in, I execute the following code: private login() { ...

What could be causing the error when running 'ng add @angular/material'?

Every time I attempt to add angular material components using the ng add command, I encounter an error stating that the package is already installed. $ ng add @angular/material Skipping installation: Package already installed Cannot find module '@a ...

Guide on invoking a promise within an observable method

In my current project, I am faced with the task of making two API calls. The second API call expects a value that is fetched from CouchDB as a promise. The method handling these calls is inherited, meaning I am unable to make modifications to it. I requir ...

Learn how to use @ngx-translate to translate text in .ts files within an Angular

Currently, I am tackling a meteor-Angular project where I am utilizing @ngx-translate for the purpose of translation. In terms of HTML files, the translation is seamless and functions perfectly using a JSON file for translation. However, when it comes to ...

Encountering Problems when Converting Vue Application from JavaScript to TypeScript with Vue and Typescript

Currently, I am in the process of converting a Vue project from JavaScript to TypeScript without utilizing the class-style syntax. These are the steps I took: I ran: vue add typescript I went through all my .vue files and: Indicated that TypeScript ...

Utilizing TypeScript Partials: Efficiently transferring selected fields between objects

I'm currently developing a feature that fetches a list of products from an E-commerce API and I want to enhance it by allowing users to request specific fields from the products while eliminating any unnecessary ones. This is the snippet of code in q ...

Creating an interactive webpage with Javascript and HTML

I'm facing a challenge with my component setup, which is structured as follows: import { Component, VERSION } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ ...