Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get data from the sublinks array

I need to get all the values for substitution in ng For, I did, but outputs only the first elements

info.component.html

 <div *ngFor="let infoItem of infoItems" class="info__item">
        <div class="info__title">{{ infoItem.title }}</div>
        <ul class="info__list">
          <li class="info__list_item"><a href="#" class="info__link">{{ infoItem.sublinks[].title }}</a></li>
        </ul>
 </div>

info.items.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export const INFO_ITEMS: IInfoItem[] = [
  {
    title: 'Company',
    sublinks: [
      {
        title: 'About CyberMetals',
      },
      {
        title: 'Careers',
      },
    ],
  },
  {
    title: 'My Account',
    sublinks: [
      {
        title: 'Registration',
      },
      {
        title: 'Account Login',
      },
    ],
  },

>Solution :

You need another *ngFor for the sublinks[] as it’s also an array.
The HMTL should be like this:

<div *ngFor="let infoItem of infoItems" class="info__item">
  <div class="info__title">{{ infoItem.title }}</div>
  <ul class="info__list">
    <div *ngFor="let sublinks of infoItem.sublinks" class="info__item">
     <li class="info__list_item">
       <a href="#" class="info__link">{{ sublinks.title }}</a>
     </li>
    </div>
  </ul>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading