數據網格 SA-數據表載荷數據:Angular2 - 僅首次
<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個記錄)。
但是,當我離開並回到相同的組件時,網格是空的。但是,ngOnInit()
中的console.log
始終記錄所有12條記錄。但他們現在剛剛在網格中顯示。
但bundles.length
打印12在桌子底下 -