Skip to content

Commit

Permalink
fix(module:list): fix does not trigger change detection correctly whe…
Browse files Browse the repository at this point in the history
…n from empty array to data array (#2199)

* fix(module:list): fix does not trigger change detection correctly when from empty array to data array

* fix document
  • Loading branch information
cipchk authored and wilsoncook committed Oct 6, 2018
1 parent e1b8761 commit 92c1a85
Showing 1 changed file with 13 additions and 40 deletions.
53 changes: 13 additions & 40 deletions components/list/nz-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// tslint:disable: no-any
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
Input,
OnChanges,
SimpleChanges,
TemplateRef
} from '@angular/core';

import { NzUpdateHostClassService } from '../core/services/update-host-class.service';
import { toBoolean } from '../core/util/convert';
import { InputBoolean } from '../core/util/convert';

import { ListSize, NzListGrid } from './interface';

Expand All @@ -32,19 +30,11 @@ import { ListSize, NzListGrid } from './interface';
` ]
})
export class NzListComponent implements OnChanges {
// region: fields
// #region fields
// tslint:disable-next-line:no-any
@Input() nzDataSource: any[] = [];

private _bordered = false;

@Input()
set nzBordered(value: boolean) {
this._bordered = toBoolean(value);
}

get nzBordered(): boolean {
return this._bordered;
}
@Input() @InputBoolean() nzBordered = false;

@Input() nzGrid: NzListGrid;

Expand Down Expand Up @@ -84,36 +74,19 @@ export class NzListComponent implements OnChanges {

@Input() nzRenderItem: TemplateRef<void>;

private _loading = false;

@Input()
set nzLoading(value: boolean) {
this._loading = toBoolean(value);
}

get nzLoading(): boolean {
return this._loading;
}
@Input() @InputBoolean() nzLoading = false;

@Input() nzLoadMore: TemplateRef<void>;

@Input() nzPagination: TemplateRef<void>;

@Input() nzSize: ListSize = 'default';

private _split = true;

@Input()
set nzSplit(value: boolean) {
this._split = toBoolean(value);
}

get nzSplit(): boolean {
return this._split;
}
@Input() @InputBoolean() nzSplit = true;

// endregion
// #endregion

// region: styles
// #region styles

private prefixCls = 'ant-list';

Expand All @@ -130,16 +103,16 @@ export class NzListComponent implements OnChanges {
[ `${this.prefixCls}-something-after-last-item` ]: !!(this.nzLoadMore || this.nzPagination || this._isFooter)
};
this.updateHostClassService.updateHostClass(this.el.nativeElement, classMap);

this.cd.detectChanges();
}

// endregion
// #endregion

constructor(private el: ElementRef, private cd: ChangeDetectorRef, private updateHostClassService: NzUpdateHostClassService) {
}

ngOnChanges(changes: SimpleChanges): void {
ngOnChanges(): void {
this._setClassMap();
// Delayed detection refresh limited by nz-spin, issues [#11280](https://github.com/angular/material2/issues/11280)
setTimeout(() => this.cd.detectChanges());
}
}

0 comments on commit 92c1a85

Please sign in to comment.