2017-04-05 48 views
0

我是新的啓動(2.0.3)。我有一個Angular 2程序,有一個公開的產品陣列。無法綁定primeng數據表

private initProductListloaded(res: product[]) 
{ 
// Public array of productList 
this.productList = res; 
} 

下面是HTML代碼

<div *ngIf="showProductGrid" style="height:400px;"> 
    <p-dataTable [value]="productList" [rows]="10"> 
    <p-column field="Sku" header="Year"></p-column> 
    <p-column field="Description" header="Brand"></p-column> 
    </p-dataTable> 
</div> 
<select name="wwindustry" style="width:100%" 
    [(ngModel)]="wselectedIndustry"> 
     <option *ngFor="let c of productList" 
     [value]="c.Sku"> c.Description}}</option> 
</select> 

下拉wwindustry是僅用於測試目的,以查看是否productList的陣列從HTML內部具有的任何數據。我試過的所有東西都無法生成數據表

回答

0

如果您在productList中有字段sku和說明,它必須顯示。確保你已經從你的module.ts文件中primeng導入了數據表。

import {DataTableModule} from 'primeng/primeng'; 

並且如果* ngIf = 「showProductGrid」 是假的也就是如果showProductGrid == false,那麼整個DIV不會在DOM渲染。確保showProductGrid值爲true或具有一定價值。

我希望這些提示可能會有所幫助ü