Skip to content

Commit 6beabf5

Browse files
committed
Fix error when input mfData is undefined
1 parent 0be9b96 commit 6beabf5

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

examples/systemjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {
2020
"angular2": "2.0.0-beta.12",
21-
"angular2-datatable": "*",
21+
"angular2-datatable": "0.3.0-dev1",
2222
"bootstrap": "^3.3.6",
2323
"es6-shim": "^0.35.0",
2424
"lodash": "^4.6.1",

examples/systemjs/src/app.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,11 @@ <h2>Simple data table</h2>
4141
<tfoot>
4242
<tr>
4343
<td colspan="4">
44-
<mfBootstrapPaginator></mfBootstrapPaginator>
44+
<mfBootstrapPaginator [rowsOnPageSet]="[5,10,15]"></mfBootstrapPaginator>
4545
</td>
4646
</tr>
4747
</tfoot>
4848
</table>
4949
</div>
50-
51-
<div>
52-
<label>Fruit</label>
53-
<input #fruit>
54-
<label>Price</label>
55-
<input #price>
56-
</div>
5750
</div>
5851
</div>

examples/systemjs/src/app.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ import {DataTableDirectives} from 'angular2-datatable/datatable';
1414
})
1515
export class App {
1616

17-
private data = [];
17+
private data;
1818

19-
constructor(private http: Http) {
19+
constructor(private http:Http) {
2020
http.get("/src/data.json")
21-
.subscribe((data)=>{
22-
this.data = data.json();
21+
.subscribe((data)=> {
22+
setTimeout(()=> {
23+
this.data = data.json();
24+
}, 5000);
2325
});
2426
}
2527

2628
private toInt(num:string) {
2729
return +num;
2830
}
2931

30-
private sortByWordLength = (a: any) => {
32+
private sortByWordLength = (a:any) => {
3133
return a.name.length;
3234
}
3335

src/DataTable.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ describe("DataTable directive tests", ()=> {
2020

2121
describe("initializing", ()=> {
2222

23+
it("data should be empty array if inputData is undefined or null", () => {
24+
let datatable = new DataTable();
25+
datatable.ngOnChanges({inputData: new SimpleChange(null, null)});
26+
datatable.ngDoCheck();
27+
expect(datatable.data).toEqual([]);
28+
});
29+
2330
it("data should be equal to inputData", ()=> {
2431
datatable.ngDoCheck();
2532
expect(datatable.data).toEqual(datatable.inputData);

src/DataTable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class DataTable implements OnChanges, DoCheck {
7272

7373
public ngOnChanges(changes:{[key:string]:SimpleChange}):any {
7474
if (changes["inputData"]) {
75+
this.inputData = this.inputData || [];
7576
this.onPageChange.emit({
7677
activePage: this.activePage,
7778
rowsOnPage: this.rowsOnPage,

0 commit comments

Comments
 (0)