数据网格:
<sa-datatable [options]="{
data: bundles,
columns: [ {data: 'srNo'}, {data: 'name'}, { data: null, defaultContent: '<button class=\'btn btn-default\'>Details</button>' } ] }"
paginationLength="true" tableClass="table table-striped table-bordered table-hover" width="100%">
<thead>
<tr>
<th data-hide="phone">Sr. No.</th>
<th data-class="expand"><i class="text-muted hidden-md hidden-sm hidden-xs"></i> Name</th>
<th></th>
</tr>
</thead>
</sa-datatable>
<div> {{bundles.length }} </div>
组件:
Component({
selector: 'tax-receipting-bundles',
templateUrl: './tax-receipting-bundles.component.html',
providers: [ TaxReceiptingBundleService ]
})
export class TaxReceiptingBundlesComponent implements OnInit {
bundles: TaxReceiptingBundle[];
constructor(private service: TaxReceiptingBundleService) {
this.bundles = [];
}
ngOnInit() {
this.service.getBundles()
.then(b=> {
this.bundles = b;
console.log(this.bundles);
});
}
服务:
@Injectable()
export class TaxReceiptingBundleService {
getBundles() {
return Promise.resolve(TAXRECEIPTINGBUNDLES);
}
}
模拟数据
export const TAXRECEIPTINGBUNDLES: TaxReceiptingBundle[] = [
{id: 1, srNo: 1, name: 'Bundles for February 2005'},
{id: 2, srNo: 2, name: 'CDN Bundles'},
.
.
{id: 12, srNo: 12, name: 'Bundles for April 2004'},
];
当我导航到包含数据网格的组件时,它会正确显示数据(12 条记录)。
但是,当我离开并返回到同一个组件时,网格是空的。但是,console.log
始终ngOnInit()
记录所有 12 条记录。但它们现在才显示在网格中。
但是bundles.length
桌子下面的印刷品 12 -