2017-04-03 8 views
12

Nie wiem, dlaczego moja pętla * ngFor niczego nie drukuje. Mam następujący kod w pliku HTML:* ngDo wyników ng-template nic Angular2

<table class="table table-hover"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Email</th> 
      <th>Company</th> 
      <th>Status</th> 
     </tr> 
    </thead> 
    <tbody> 
     <!-- NGFOR ATTEMPTED HERE -- no content printed --> 
     <ng-template *ngFor="let xb of tempData"> 
      <tr data-toggle="collapse" data-target="#demo1" class="accordion-toggle"> 
       <td>{{ xb.name }}</td> 
       <td>{{ xb.email }}</td> 
       <td>{{ xb.company }}</td> 
       <td>{{ xb.status }}</td> 
      </tr> 
      <!-- other content --> 
     </ng-template> 
    </tbody> 
</table> 

Następnie w moim prostym składnikiem Mam następujący:

import { Component }  from '@angular/core'; 

@Component({ 
    selector: 'my-profile-exhibitors', 
    templateUrl: './profile-exhibitors.component.html', 
    styleUrls: ['./profile-exhibitors.component.scss'] 
}) 
export class ProfileExhibitorsComponent { 
    public tempData: any = [ 
     { 
      'name': 'name1', 
      'email': '[email protected]', 
      'company': 'company', 
      'status': 'Complete' 
     }, 
     { 
      'name': 'name2', 
      'email': '[email protected]', 
      'company': 'company', 
      'status': 'Incomplete' 
     } 
    ]; 
    constructor() {} 
} 

Kiedy uruchomić ten kod, mam zerowe wyjście. Jeszcze dziwniejsze jest to, że po zaznaczeniu elementu za pomocą narzędzi debugowania widzę tak:

enter image description here

Wygląda na to, że poprawnie rozpoznaje mój obiekt, ale następnie wyświetla nic.

Odpowiedz

26

myślę co chcesz to

<ng-container *ngFor="let xb of tempData"> 

lub

<ng-template ngFor let-xb [ngForOf]="tempData"> 
+7

Dzięki! I ktokolwiek zaprojektował składnię dla 'ng-template', musi być spalony na stosie –

+0

Nie jestem pewien, na co narzekasz. Jest to normalna składnia szablonowa kątowa. Wprowadzili '', aby móc użyć bardziej zwięzłej i bardziej powszechnej składni '* xxx' na'