Skip to content

Commit

Permalink
fix(module:table): fix nzWidth with ngIf (#349)
Browse files Browse the repository at this point in the history
close #302
  • Loading branch information
vthinkxie authored Sep 22, 2017
1 parent aec9f83 commit d5d379b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/components/table/nz-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
Output,
ContentChild,
ChangeDetectorRef,
TemplateRef, OnInit
TemplateRef, OnInit, ContentChildren, QueryList
} from '@angular/core';
import { measureScrollbar } from '../util/mesureScrollBar';
import { NzThDirective } from './nz-th.directive';

@Component({
selector : 'nz-table',
Expand Down Expand Up @@ -112,6 +113,11 @@ export class NzTableComponent implements AfterViewInit, OnInit {
@Input() nzShowTitle = false;
@ContentChild('nzFixedHeader') fixedHeader: TemplateRef<any>;

@ContentChildren(NzThDirective, { descendants: true })
set setThs(value: QueryList<NzThDirective>) {
this.ths = value.toArray();
}

@Input()
set nzScroll(value) {
this._scroll = value;
Expand Down
18 changes: 3 additions & 15 deletions src/components/table/nz-th.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@ import {
Directive,
Input,
HostBinding,
ElementRef, OnInit, OnDestroy
ElementRef
} from '@angular/core';
import { NzTableComponent } from './nz-table.component';

@Directive({
selector: '[nz-th]'
})
export class NzThDirective implements OnInit, OnDestroy {
export class NzThDirective {
_el: HTMLElement;
@Input() nzWidth;
@Input() @HostBinding(`class.ant-table-selection-column`) nzCheckbox;
@Input() @HostBinding(`class.ant-table-expand-icon-th`) nzExpand;

constructor(private _elementRef: ElementRef, private nzTableComponent: NzTableComponent) {
constructor(private _elementRef: ElementRef) {
this._el = this._elementRef.nativeElement;
}

ngOnInit() {
this.nzTableComponent.ths.push(this);
}

ngOnDestroy() {
const index = this.nzTableComponent.ths.indexOf(this);
if (index > -1) {
this.nzTableComponent.ths.splice(index, 1);
}
}
}

0 comments on commit d5d379b

Please sign in to comment.