I have a Template like this
Component.html
<h1>aditya</h1>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<table class="table table-bordered">
<thead>
<tr>
<th style="white-space: nowrap" *ngFor="let columns of data?.display_columns; let i = index">{{columns}}</th>
</tr>
<tr *ngFor="let row1 of data?.row1; let i= index">
<td style="white-space: nowrap" *ngFor="let columns of data?.display_columns; let i = index">{{row1[columns]}}</td>
</tr>
</thead>
</table>
</div>
</div>
Component.ts
import { Component, OnInit } from '@angular/core';
import { HttpModule } from '@angular/http';
import { SpreadsheetService } from '../dataservice/spreadsheet.service';
@Component({
moduleId: module.id,
selector: 'sd-list-view',
templateUrl: 'list-view.component.html',
styleUrls: ['list-view.component.css'],
providers: [HttpModule, ListService]
})
export class ListViewComponent implements OnInit {
data: any;
spreadsheet: any;
data1: any;
isDataAvailable: boolean = false;
constructor(public _spreadsheetService: SpreadsheetService) {
}
ngOnInit() {
this._spreadsheetService.getData()
.subscribe(data => {
this.data = data;
(<any>window)['mydata'] = (data);
console.log(this.data.display_columns);
var data1: any;
//alert('get data');
return this.data;
});
//alert('list view 2');
}
}
The first line of the template "Aditya" is getting displayed but the data table inside the loop is not loading on the Component Initialization.
How can I run the loop and load the data before the View is initialized or another case be to load the Table data after the View is initialized?
PS: The loop is tested and working. I don't want to use APP_Initializer.
I have gone through this question but could not understand the solution as I am using Observables instead of Promise.
Thanks in Advance.