Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
How to populate list in list in a table Angular

I have a list of values [1, paracetamol,[{1, location, quantity}, {2, location2, quantity}] so I have to print in two rows 1. [1, paracetamol, location, quantity] 2. [2. paracetamol, location1, quantity2]

I have maintained head headElements = ['Drug ID', 'Drug Name', 'Location', 'Quantity']

      <table  class="table table-striped" >
                        <thead>
                         <tr>
                             <th *ngFor="let head of headElements" scope="col">{{ head }}</th>
                          </tr>
                        </thead>
                        <tbody> 
                            <div *ngFor = "let drugDetail of drugList">

                                <tr  *ngFor="let loc of drugDetail.drugLocationList">
              
                                  <th scope="row">{{ drugDetail.drugId }}</th>
              
                                  <td>{{ drugDetail.drugName  }}</td>
              
                                   <td>{{loc.location}}</td>
                
                                  <td>{{ loc.quantity}}</td>
                                </tr>
                              </div>
        
                      </table>

output:

['Drug ID',                         'Drug Name', 'Location', 'Quantity']
[1, paracetamol, location, quantity]
[2. paracetamol, location1, quantity2]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe it could be easier if you do first a map to your array data, something like this:


copyDrugList = drugList.map(drugDetail => [
{  drugId    : drugDetail.drugLocationList[0].drugId   ,
   drugName  : drugDetail.drugName ,
   location  : drugDetail.drugLocationList[0].location ,
   quantity  : drugDetail.drugLocationList[0].quantity ,
},
{  drugId    : drugDetail.drugLocationList[0].drugId   ,
   drugName  : drugDetail.drugName ,
   location  : drugDetail.drugLocationList[1].location ,
   quantity  : drugDetail.drugLocationList[1].quantity ,
},
]);

Then, you only need to do a classic Angular HTML ngFor:

<tr *ngFor = "let drugDetail of copyDrugList ">
   <td>{{ drugDetail.drugId    }}</td>
   <td>{{ drugDetail.drugName  }}</td>
   <td>{{ drugDetail.location  }}</td>
   <td>{{ drugDetail.quantity  }}</td>
</tr>
                      
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda