2017-07-18 11 views
1

私のAngularプログラムでは、離陸したすべての日を含む配列の各人物のテーブルをプリントアウトしようとしています。従業員が配列されている配列はempInfoで、離した日の配列はptoDataです。両方の配列のフィールドはEmpKeyです。別のngForの内部でngForを使用しますか?

ここで私はこれまで試したものです:

enter image description here

を私は<ng-container *ngIf="pto.EmpKey === emp.EmpKey"></ng-container>を削除した場合、それは印刷します

 <div class="panel-body" style="padding-left: 0px;" *ngFor="let emp of empInfo"> 
 
     <table> 
 
      <thead> 
 
      <tr>Employee: {{emp.EmpKey}} {{emp.FirstName}} {{emp.LastName}}</tr> 
 
      <tr> 
 
       <td>Date</td> 
 
       <td>Hours</td> 
 
       <td>Scheduled</td> 
 
       <td>Notes</td> 
 
      </tr> 
 
      </thead> 
 
      <tbody> 
 
      <ng-container *ngIf="pto.EmpKey === emp.EmpKey"> 
 
       <ng-container *ngFor="let pto of of ptoData"> 
 
       <tr> 
 
        <td>{{pto.date}}</td> 
 
        <td>{{pto.hours}}</td> 
 
        <td>{{pto.scheduled}}</td> 
 
        <td>{{pto.notes}}</td> 
 
       </tr> 
 
       </ng-container> 
 
      </ng-container> 
 
      </tbody> 
 
     </table> 
 
     </div>

が、ここではそれをプリントアウトだことすべてですこれは(これはまだ私が明らかに探しているものではありませんが、少なくともプリントします名)から:

enter image description here

+1

'* ngFor = "ptoDataのを聞かせてPTOを"'間違って見えます。 '* ngIf'と' * ngFor'の順番も間違っているようです。 – pzaenger

答えて

1

あなたは<ng-container>タグを切り替える必要があり、pto変数が第一の容器ではまだ知られていません。 pzaengerが言うように、はい、あなただけの*ngForで1 of使用;)

<ng-container *ngFor="let pto of ptoData"> 
    <ng-container *ngIf="pto.EmpKey === emp.EmpKey"> 
     <tr> 
     <td>{{pto.date}}</td> 
     <td>{{pto.hours}}</td> 
     <td>{{pto.scheduled}}</td> 
     <td>{{pto.notes}}</td> 
     </tr> 
    </ng-container> 
</ng-container> 
+0

ありがとう、大変感謝しています!私はhahaの二重に気づいていなかった – asdf

+1

も ​​'tr'タグで' * ngIf'を使うべきです。ここに余分な 'ng-container 'を追加しても意味がありません。 – snaplemouton