Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
How to render all subarrays elements of array in Angular?

I have an array like this:

type categories = {
  name: string;
  sub?: categories[];
};

categories: Array<categories> =
[{ name: 'C1',
      sub: [{name: 'S1',
        },
        {name: 'S2',
          sub: [{ name: 'SS1',
               sub: [{ name: 'SSS1',
                },
                { name: 'SSS2',
                },],
          },],
      },],
},];

Every sub can have unlimited subs. How can I render all elements of all subarrays?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can recursively nest components like so:

@Component({
  selector: 'example-component',
  template: `
    <div *ngFor="let nestedCategory of nestedCategories.sub">
      <div>{{nestedCategory.name}}</div>
      <div *ngIf="nestedCategory.sub">
        <example-component [nestedCategories]="nestedCategory.sub"></example-component>
      </div>
    </div>
  `
})
export class ExampleComponent {
  @Input('nestedCategories') nestedCategories!: Array<categories>;
}

Then in your parent component template you can declare it as follows:

<example-component [nestedCategories]="categories"></example-component>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!