]);
});
});
+
+ describe('subscribe fetchData', () => {
+ it('should not subscribe fetchData of table', () => {
+ component.ngOnInit();
+ expect(component.table.fetchData.observers.length).toBe(0);
+ });
+
+ it('should call fetchData', () => {
+ let called = false;
+ component.fetchData.subscribe(() => {
+ called = true;
+ });
+ component.ngOnInit();
+ expect(component.table.fetchData.observers.length).toBe(1);
+ component.table.fetchData.emit();
+ expect(called).toBeTruthy();
+ });
+ });
});
-import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
+import {
+ Component,
+ EventEmitter,
+ Input,
+ OnChanges,
+ OnInit,
+ Output,
+ ViewChild
+} from '@angular/core';
import * as _ from 'lodash';
import { CellTemplate } from '../../enum/cell-template.enum';
import { CdTableColumn } from '../../models/cd-table-column';
+import { TableComponent } from '../table/table.component';
/**
* Display the given data in a 2 column data table. The left column
})
export class TableKeyValueComponent implements OnInit, OnChanges {
- columns: Array<CdTableColumn> = [];
+ @ViewChild(TableComponent)
+ table: TableComponent;
@Input() data: any;
@Input() autoReload: any = 5000;
-
@Input() renderObjects = false;
// Only used if objects are rendered
@Input() appendParentKey = true;
+ columns: Array<CdTableColumn> = [];
tableData: {
key: string,
value: any
flexGrow: 3
}
];
+ // We need to subscribe the 'fetchData' event here and not in the
+ // HTML template, otherwise the data table will display the loading
+ // indicator infinitely if data is only bound via '[data]="xyz"'.
+ // See for 'loadingIndicator' in 'TableComponent::ngOnInit()'.
+ if (this.fetchData.observers.length > 0) {
+ this.table.fetchData.subscribe(() => {
+ // Forward event triggered by the 'cd-table' data table.
+ this.fetchData.emit();
+ });
+ }
this.useData();
}
}
return v;
}
-
- reloadData() {
- // Forward event triggered by the 'cd-table' datatable.
- this.fetchData.emit();
- }
}