This repository was archived by the owner on Feb 2, 2025. It is now read-only.
This repository was archived by the owner on Feb 2, 2025. It is now read-only.
Loading dtOptions later because of using a Promise/Observable #980
Closed
Description
I am using an Observable to load data that is used to load information about which columns to display. So this information needs to go into dtOptions. How do I make the directive wait for the dtOptions to be set?
What versions you are using?
- angular version: 2.4
- jquery version: 3.1.1
- datatables version: 1.10.13
- angular-datatables version: 2.1.0
What's the problem?
I get an error, probably because the datatable tries to initialize before the dtOptions are set. If I place the data directly in dtOptions without using the Http class, it works.
EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'aDataSort' of undefined
TypeError: Cannot read property 'aDataSort' of undefined
Can you share your code?
table.template.html:
<table datatable [dtOptions]="dtOptions" class="dataTable row-border hover"></table>
table.component.ts (shortened):
import { Http } from '@angular/http';
export class Table {
dtOptions: any = {};
constructor(private http:Http) { }
ngOnInit(): void {
this.http.get('app/table/table.config.json')
.subscribe(res => {
this.dtOptions = res.json();
});
}