我正在尝试为对象数组中的每个对象创建一个单独的 PrimeNG DataTable。我尝试使用 *ngFor 循环创建它以遍历数组并将每个实例分配给一个表。这显示在这里:
ReferencePage.component.html:
<div *ngFor="let freight of freights; let i = index ">
<p-panel panelStyleClass="panelborder" header="Freight Piece {{i}}"
[toggleable]="true">
<p-dataTable [value]="freight" editable="true" styleClass="headercolor"
[style]="{'width':'95%'}">
<p-column field="shipper" editable="true" header="Shipper"></p-column>
<p-column field="packinghouse" editable="true" header="Vendor"></p-column>
<p-column field="pustreet" header="Street"></p-column>
<p-column field="pucity" header="City"></p-column>
<p-column field="pustate" [style]="{'width':'50px'}" header="State"></p-column>
<p-column field="puzip" [style]="{'width':'70px'}" header="Zip"></p-column>
<p-column field="pucarrier" editable="true" header="Carrier"></p-column>
<p-column field="pudriver" editable="true" header="Driver"></p-column>
<p-column field="pustatus" editable="true" header="Status"></p-column>
<p-column field="punumber" editable="true" header="PU #"></p-column>
<p-column field="region" [style]="{'width':'60px'}" editable="true" header="Region"></p-column>
<p-column field="pudate" editable="true" header="Date"></p-column>
<p-column field="putime" [style]="{'width':'60px'}" editable="true" header="Time"></p-column>
<p-column field="puappt" editable="true" header="Appt"></p-column>
</p-dataTable>
<div class="buttons">
<button>Problems</button>
<button>Driver Note</button>
</div>
</p-panel>
<br/>
</div>
但是当我这样做时,我收到以下错误: 我的错误消息
这是我的ts:
ReferencePage.component.ts:
import { Component, OnInit, Input } from '@angular/core';
import { DataTableModule, SharedModule } from 'primeng/primeng';
import { Observable, Subscription } from 'rxjs/Rx';
import { ButtonModule } from 'primeng/primeng';
import { OverlayPanel, PanelModule } from 'primeng/primeng';
import { freightpiece, manifest } from '../shipmentobject';
import { StopService } from '../DeliveryScreen/Services/stop.service';
import 'rxjs/add/observable/of';
@Component({
selector: 'referencepage',
styleUrls: ['./ReferencePage.component.css'],
templateUrl: './ReferencePage.component.html',
providers: [StopService]
})
export class referencepage implements OnInit {
currentRefNumber: string;
freightnumber: 0;
tests = [1,2,3,4,5];
freights: freightpiece[];
constructor(private stopservice: StopService){}
ngOnInit(){
//currentRefNumber = router parameter
this.currentRefNumber = '999900';
console.log(this.currentRefNumber);
this.stopservice.search4(this.currentRefNumber)
.subscribe((res: freightpiece[]) => this.freights = res)
}
}