mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
perf(table): cell references not being cleaned up on destroy (#5809)
This commit is contained in:
committed by
Kara
parent
0adb2abcd1
commit
df1ddeee7b
@@ -155,6 +155,19 @@ describe('CdkTable', () => {
|
||||
expect(changedRows[2].getAttribute('initialIndex')).toBe(null);
|
||||
});
|
||||
|
||||
it('should clear the row view containers on destroy', () => {
|
||||
const rowPlaceholder = fixture.componentInstance.table._rowPlaceholder.viewContainer;
|
||||
const headerPlaceholder = fixture.componentInstance.table._headerRowPlaceholder.viewContainer;
|
||||
|
||||
spyOn(rowPlaceholder, 'clear').and.callThrough();
|
||||
spyOn(headerPlaceholder, 'clear').and.callThrough();
|
||||
|
||||
fixture.destroy();
|
||||
|
||||
expect(rowPlaceholder.clear).toHaveBeenCalled();
|
||||
expect(headerPlaceholder.clear).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('with trackBy', () => {
|
||||
|
||||
let trackByComponent: TrackByCdkTableApp;
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
TrackByFunction,
|
||||
ViewChild,
|
||||
ViewContainerRef,
|
||||
ViewEncapsulation
|
||||
ViewEncapsulation,
|
||||
} from '@angular/core';
|
||||
import {CollectionViewer, DataSource} from './data-source';
|
||||
import {CdkCellOutlet, CdkCellOutletRowContext, CdkHeaderRowDef, CdkRowDef} from './row';
|
||||
@@ -175,8 +175,11 @@ export class CdkTable<T> implements CollectionViewer {
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this._rowPlaceholder.viewContainer.clear();
|
||||
this._headerRowPlaceholder.viewContainer.clear();
|
||||
this._onDestroy.next();
|
||||
this._onDestroy.complete();
|
||||
|
||||
if (this.dataSource) {
|
||||
this.dataSource.disconnect(this);
|
||||
}
|
||||
@@ -343,7 +346,7 @@ export class CdkTable<T> implements CollectionViewer {
|
||||
viewRef.context.first = index === 0;
|
||||
viewRef.context.last = index === count - 1;
|
||||
viewRef.context.even = index % 2 === 0;
|
||||
viewRef.context.odd = index % 2 !== 0;
|
||||
viewRef.context.odd = !viewRef.context.even;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user