An endless cascade of dots appears as the list items are being rendered

Struggling to display intricately nested list elements,

Take a look at the JSON configuration below:

listItems = {
  "text": "root",
  "children": [{
    "text": "Level 1",
    "children": [{
      "text": "Level 2",
      "children": [{
        "text": "Level 3",
        "children": [],
        "type": "unordered-list-item"
      }],
      "type": "unordered-list-item"
    }],
    "type": "unordered-list-item"
  }],
  "type": "unordered-list-item"
}

The HTML structure for my component is shown below:

<ul *ngIf="listItems.type === 'unordered-list-item' && listItems.children.length > 0">
  <li *ngFor="let child of listItems.children">
    {{ child.text }}

    <bw-list *ngIf="child.type === 'unordered-list-item'" [listItem]="child"></bw-list>
  </li>
</ul>

When children are present, the component should iterate and render them.

Component.ts

export class AppComponent {
  @Input() listItem: any;
  public listItems = {
    "text": "root",
    "children": [{
      "text": "Level 1",
      "children": [{
        "text": "Level 2",
        "children": [{
          "text": "Level 3",
          "children": [],
          "type": "unordered-list-item"
        }],
        "type": "unordered-list-item"
      }],
      "type": "unordered-list-item"
    }],
    "type": "unordered-list-item"
  };
}

The issue faced currently is the rendering of endless bullet points. Seeking assistance on this matter.

Explore the project further via this link.

Answer №1

Your code seems to be missing a step in reducing the length number. Here's a possible solution for you to consider:

import {Component, Input} from "@angular/core";

@Component({
    selector: 'my-app',
    template: `
    <div>
      Recursive Component
      <my-app [counter]="counter - 1" *ngIf="counter > 0"></my-app>
    </div>
  `
})
export class AppComponent {

    @Input() counter : number = 3;

}

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

Is it necessary to create a unit test for a basic operation involving RxJS?

Imagine a straightforward class that triggers a new event to an RxJS subject whenever the window is resized. Disregard any perceived complexities, as the main point is that this class generates an event. export class ResizeService { priv ...

Anticipating the desired data types for Jasmine arguments

Lately, I've been in the process of upgrading my Angular version from 10 to 13 in order to utilize TypeScript 4.6. However, during this upgrade, I made some errors with types in my tests and I'm wondering if others have encountered similar issues ...

Obtaining Data from an Array with Reactive Forms in Angular 4

Just starting out with Angular 4 and trying to figure out how to populate input fields with information based on the selection made in a dropdown. <select formControlName="selectCar" class="form-field"> <option value="">Choose a car&l ...

Creating a custom component in Angular 2 that includes several input fields is a valuable skill to have

I have successfully created a custom component in Angular 2 by implementing the CustomValueAccessor interface. This component, such as the Postcode component, consists of just one input field. <postcode label="Post Code" cssClass="form-control" formCon ...

Is bundling a Node.js backend a wise decision or a mistake?

Just a thought that crossed my mind - I understand the advantages of bundling client-side code, but what about bundling server-side code with Browserify/Webpack? Is this considered a best practice? ...

Issue with rejecting a promise within a callback function in Ionic 3

Within my Ionic 3 app, I developed a function to retrieve a user's location based on their latitude and longitude coordinates. This function also verifies if the user has location settings enabled. If not, it prompts the user to switch on their locati ...

Leverage Ramda's clone function within a pipeline in a manner that ensures type safety

My goal is to utilize Ramda for cloning and updating objects in a type-safe manner, drawing inspiration from this approach. However, I am facing challenges implementing it in a type-safe way. Updating a nested object seems to work perfectly fine in a type ...

Looking for a youtube.d.ts file to integrate the youtube-iframe-api with Angular 2?

My current challenge involves implementing the youtube iframe api for seamless video snippet display and control within an Angular 2 application. Maintaining TypeScript's type concept is crucial for both the webpack compiler and myself :). A brief ov ...

Unable to create an Ionic module with routing using Angular

Having trouble generating modules with routing in my Ionic project. After creating a new Ionic project using ionic start routing blank, I attempted to generate a module with routing by entering the following commands: ionic g m heroes --route heroes --mo ...

Encountering issues with @typescript-eslint/typescript-estree due to using a non-officially supported version of TypeScript after updating Nuxt

After upgrading Nuxt in my project using the command npx nuxi upgrade, I encountered an issue while running eslint .. The output displayed a warning regarding the TypeScript version: ============= WARNING: You are currently running a version of TypeScript ...

The utilization of conditional expression necessitates the inclusion of all three expressions at the conclusion

<div *ngFor="let f of layout?.photoframes; let i = index" [attr.data-index]="i"> <input type="number" [(ngModel)]="f.x" [style.border-color]="(selectedObject===f) ? 'red'" /> </div> An error is triggered by the conditional ...

Discovering the origins of the node.js native modules and delving into the intricacies of typed modules

I am using a Windows machine and trying to locate where node fetches the source code for native modules. On my system, I can only find the @types file which contains "Typed Only" modules. For example, the module "assert" is available in the master/lib fold ...

How can the service worker be incorporated into an Angular library?

I'm currently working on creating an npm package that will notify users to refresh the page when there's a build update in different projects. I believe using a service worker in Angular can help achieve this concept, however, I encountered an er ...

Unable to bind to ngModel as it returned as "undefined" in Angular 8

Whenever I bind a property to ngModel, it consistently returns undefined <div> <input type="radio" name="input-alumni" id="input-alumni-2" value="true" [(ngModel) ...

The connection between Cognito identity and Mqtt is not possible within AWS IoT Core

The application is built using Angular. Upon logging in with Cognito, the application retrieves the user's CognitoUser data, including id token, access key, and session token. Next, the application connects to Iot Core to subscribe to or publish data ...

Exploring Angular 2 Application Testing: Tips for Interacting with HTML Elements

In my Angular 2 Frontend testing journey, I came across a blog post ( ) where the author utilized ng-test TestBed for core testing in Angular. While the example provided was helpful for basic understanding, it lacked details on how to manipulate Elements. ...

Mistakes in combining Angular NgRx actions and union types

After reviewing my code, I have encountered the following issues: In my shared.actions.ts file: import { Action } from '@ngrx/store'; import { Error } from '../error.interface'; export const types = { IS_LOADING: '[SHARED] IS_L ...

An error occurs when trying to use AWS.Comprehend as a constructor in the aws JavaScript SDK

I'm attempting to utilize the Amazon Comprehend API using the AWS JavaScript SDK. However, I keep encountering Uncaught (in promise): TypeError: undefined is not a constructor (evaluating 'new AWS.Comprehend... ' What am I doing incorr ...

`The utilization of a collective interface/data type within an Angular application`

I created a HeaderComponent that requires an object with the structure of {title: string, short_desc: string} as its input property. @Component({ selector: 'header', templateUrl: './header.component.html', styleUrls: ['./hea ...

Issue with HTTP interceptor failing to activate

I'm having trouble with my interceptor not triggering. Despite trying multiple solutions, I can't seem to get it working. The interceptor is failing to intercept http requests, resulting in the 'Authorization' header not being added. ...