What is the best way to create a nested *ngFor loop using FirebaseList?

Looking to implement a nested *ngFor using Firebase data with angularFire2.

The data structure is as follows: https://i.sstatic.net/UG7ml.png

I aim to iterate through the first level of subjects list in one *ngFor, and then loop through the child level in a nested *ngFor.

<ion-list>
    <ion-item *ngFor="let mainSubject of subjects | async">
        {{mainSubject.name}}
        <ion-list>
            <ion-item *ngFor="let childSubject of mainSubject.subjects | async">
                {{childSubject.name}}
            </ion-item>
        </ion-list>
    </ion-item>
</ion-list>

Considering using the map operator from rxjs for list transformation:

this.db.list(`${this.mainSubjectsPath}`).map((value) => {
    console.log(value);
    // perform necessary transformations...
});

However, it seems like the map function isn't being called.

Any suggestions on how to approach this?

Thank you!

Answer №1

This particular issue arises when attempting to loop through an Object (subjects) in angular templates, as *ngFor is only applicable to arrays.

To address this error, consider the following solutions:

  • Revise your data structure to iterate over array elements instead.
  • Create a custom pipe for looping through objects. An example can be found here.

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

Troubles encountered with fetching pre-filled values in Angular form automation

In my project, there is a template driven angular form for the Edit profile section in the app. Data is populated from the API for the form, with fields being empty if no data is available. When a user types new data into the fields, it is successfully pos ...

A guide on showcasing nested arrays data in an Angular application

info = [ { list: [ { title: 'apple'} ] }, { list: [ { title: 'banana'} ] } ] My goal here is to extract the list items. Here is how they are structured. desired r ...

How can one effectively broaden the interface of an object in TypeScript that is already implementing an interface in an idiomatic manner?

In my TypeScript project, I have defined these DTO interfaces: interface ProductDto { readonly productId: number; readonly name : string; } interface FirstPartyProductDto extends ProductDto { readonly foo: string; readonly bar: number; ...

Is array.length access cached by NodeJS?

Lately, I've been pondering whether accessing the array.length getter is cached by NodeJS. I've searched for conclusive answers about JS interpretation in browsers, but since I am working on apps in Typescript, that information does not directly ...

Learn the steps to assign a Base64 URL to an image source

I am currently facing an issue with an image that is being used with angular-cli: <img src="" style="width: 120px; padding-top: 10px" alt="" id="dishPhoto"> The image has a Base64 url named imgUrl. My intention is to set the image source using the ...

What method enables TypeScript's core.ts to build successfully without encountering an overload error?

These few lines of code demonstrate a TypeScript function called sameFlatMap, which deals with mapping and flattening arrays. The function offers three signature overloads, catering to different array types and mapping functions. export function sameFlatM ...

Transforming text into numbers from JSON response with *ngFor in Angular 6

I'm currently attempting to convert certain strings from a JSON response into numbers. For instance, I need to change the zipcode value from "92998-3874" to 92998-3874. While doing this, I came across a helpful resource on Stack Overflow. However, I s ...

Tips for ensuring the dropdown model loads only after the dropdown options have fully loaded in Angular 9 without interfering with the asynchronous nature of the code

I am facing an issue with my primeng dropdown and service calls. I have one service call to retrieve dropdown options and another one for model binding data. After saving the selected value and reloading the page, sometimes the selected value is not displa ...

Encountering a SyntaxError: Unexpected or invalid token during the upgrade process to NewRelic version 9

After upgrading the NewRelic agent to version 9 or above, some of my services started encountering an error which was not present in NewRelic version 8. One service is built on Node 14 and another on Node 16, both using Typescript 4.9.5. node_modules/newre ...

Receive a failure message from ngrx@effects and pass it to the component

I am encountering an issue with setting up server error validation for each input field in a form. The challenge lies in the fact that I am using ngrx@store, which presents a complication. @Effect({ dispatch: false }) error$ = this.actions$.pipe( o ...

How to change the divider color in Angular Material table's header row

Currently struggling with customizing the divider appearance in the Angular Material table. Despite trying various approaches in the Chrome dev tools, I am unable to modify the color and thickness of the divider after the header row. It seems that the bord ...

Invalid NPM package detected while deploying: @types

As I try to set up my first application with Azure's continuous development, I am facing some issues. The app is a standard template from Visual Studio 2017 MVC net core 2.0, using React. After pushing the app to my GitHub repository and configuring a ...

When deciding between StoreModule.forRoot and StoreModule.forFeature, consider the specific needs of your application

After researching, I discovered that the .forRoot function merges all reducers, allowing you to manipulate multiple reducers simultaneously when manipulating the state. On the other hand, the .forFeature function gives you the ability to manipulate each r ...

An issue has been detected within the upperCaseComponent template component

An issue has been detected with the template: Here are the errors found: The property 'result' is private and can only be accessed within the 'upperCaseComponent' class The property 'mymessage' is not declared in the &apos ...

Persist List<Model> to SQLite

Currently, I am developing an application using Firebase and I need to save a large list of over 5000 PricesList items into SQLite. This is the Firebase code I have so far: @Override protected void onStart() { super.onStart(); mRef.addValueEvent ...

Encountering a redeclaration issue in Angular 8 while including an external JavaScript file

I have manually added an external JS script to my component. The script is functioning correctly, but when I try to inject it again, I encounter issues. var div = this.document.getElementById("div-element"); div.appendChild(script); My attempt t ...

Developing a React application using VSCode and Typescript within a Docker container

Currently, I am working with typescript and create-react-app on my local machine for development purposes. To streamline the process, I have removed the node_modules directory since it becomes unnecessary once all dependencies are installed via an image. W ...

Accessing a variable within a function in Angular

Recently I started working with Angular and encountered an issue while trying to access a variable inside a function. Below is the code snippet that's causing me trouble: mergeImages() { var imgurl; var canvas: HTMLCanvasElement = this.canv ...

Validation of emails in Angular through the utilization of reactive forms

Hello there, I'm new to Angular and looking for some assistance. Specifically, I am currently working on validating an email input using a reactive form with the keyup event. registerform:any; ngOnInit(): void { this.registerform = new F ...

A more efficient method for incorporating types into props within a functional component in a TypeScript-enabled NextJS project

When dealing with multiple props, I am looking for a way to add types. For example: export default function Posts({ source, frontMatter }) { ... } I have discovered one method which involves creating a wrapper type first and then defining the parameter ty ...