2017-04-03 17 views
12

यह सुनिश्चित नहीं है कि मेरा * ngFor लूप कुछ भी क्यों प्रिंट नहीं कर रहा है।* एनजी-टेम्पलेट आउटपुट पर ngFor कुछ भी नहीं कोणीय 2

<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> 

फिर, मेरे सरल घटक में मैं निम्नलिखित है:

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() {} 
} 

मुझे इस कोड चलाने के लिए, मैं शून्य आउटपुट प्राप्त मैं एक HTML फ़ाइल में निम्न कोड की है। भी weirder कि जब मैं डिबग उपकरण का उपयोग कर तत्व का चयन मैं यह देख रहा है:

enter image description here

ऐसा लगता है कि इसे सही ढंग से मेरी वस्तु को पहचानता है, लेकिन फिर कुछ भी नहीं आउटपुट।

उत्तर

26

मुझे लगता है कि क्या आप चाहते

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

या

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

धन्यवाद! और जो भी 'एनजी-टेम्पलेट' के लिए सिंटैक्स डिज़ाइन किया गया है उसे –

+0

पर जला दिया जाना चाहिए, यह सुनिश्चित नहीं है कि आप किस बारे में शिकायत कर रहे हैं। यह सामान्य कोणीय टेम्पलेट वाक्यविन्यास है। उन्होंने '