|
1 | 1 | import { |
2 | 2 | Component, ChangeDetectionStrategy, Input, Output, EventEmitter, ContentChild, ViewChildren, |
3 | 3 | QueryList, ViewChild, TemplateRef, DoCheck, AfterContentInit, HostBinding, |
4 | | - OnInit, AfterViewInit, ContentChildren, CUSTOM_ELEMENTS_SCHEMA, booleanAttribute |
| 4 | + OnInit, AfterViewInit, ContentChildren, CUSTOM_ELEMENTS_SCHEMA, booleanAttribute, OnDestroy, |
5 | 5 | } from '@angular/core'; |
6 | 6 | import { NgIf, NgTemplateOutlet, NgClass, NgFor, NgStyle } from '@angular/common'; |
7 | 7 |
|
@@ -47,7 +47,7 @@ import { IgxCircularProgressBarComponent } from '../../progressbar/progressbar.c |
47 | 47 | import { IgxOverlayOutletDirective, IgxToggleDirective } from '../../directives/toggle/toggle.directive'; |
48 | 48 | import { IgxSummaryRowComponent } from '../summaries/summary-row.component'; |
49 | 49 | import { IgxGridRowComponent } from './grid-row.component'; |
50 | | -import { IgxTemplateOutletDirective } from '../../directives/template-outlet/template_outlet.directive'; |
| 50 | +import { IgxTemplateOutletDirective, IViewChangeEventArgs } from '../../directives/template-outlet/template_outlet.directive'; |
51 | 51 | import { IgxColumnMovingDropDirective } from '../moving/moving.drop.directive'; |
52 | 52 | import { IgxGridDragSelectDirective } from '../selection/drag-select.directive'; |
53 | 53 | import { IgxGridBodyDirective } from '../grid.common'; |
@@ -157,7 +157,7 @@ export interface IGroupingDoneEventArgs extends IBaseEventArgs { |
157 | 157 | ], |
158 | 158 | schemas: [CUSTOM_ELEMENTS_SCHEMA] |
159 | 159 | }) |
160 | | -export class IgxGridComponent extends IgxGridBaseDirective implements GridType, OnInit, DoCheck, AfterContentInit, AfterViewInit { |
| 160 | +export class IgxGridComponent extends IgxGridBaseDirective implements GridType, OnInit, DoCheck, AfterContentInit, AfterViewInit, OnDestroy { |
161 | 161 | /** |
162 | 162 | * Emitted when a new chunk of data is loaded from virtualization. |
163 | 163 | * |
@@ -443,7 +443,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType, |
443 | 443 | return this.gridAPI as IgxGridAPIService; |
444 | 444 | } |
445 | 445 |
|
446 | | - private childDetailTemplates: Map<any, any> = new Map(); |
| 446 | + private childDetailTemplates: Map<any, IViewChangeEventArgs> = new Map(); |
447 | 447 |
|
448 | 448 | /** |
449 | 449 | * @hidden @internal |
@@ -953,16 +953,19 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType, |
953 | 953 | /** |
954 | 954 | * @hidden @internal |
955 | 955 | */ |
956 | | - public viewCreatedHandler(args) { |
| 956 | + public viewCreatedHandler(args: IViewChangeEventArgs) { |
957 | 957 | if (args.context.templateID.type === 'detailRow') { |
958 | 958 | this.childDetailTemplates.set(args.context.$implicit, args); |
| 959 | + |
| 960 | + // Claim ownership so life-cycle will be managed by the Grid |
| 961 | + args.owner.claimOwnership(args.context.templateID.type, args.context.templateID.id, args.view); |
959 | 962 | } |
960 | 963 | } |
961 | 964 |
|
962 | 965 | /** |
963 | 966 | * @hidden @internal |
964 | 967 | */ |
965 | | - public viewMovedHandler(args) { |
| 968 | + public viewMovedHandler(args: IViewChangeEventArgs) { |
966 | 969 | if (args.context.templateID.type === 'detailRow') { |
967 | 970 | // view was moved, update owner in cache |
968 | 971 | const key = args.context.$implicit; |
@@ -1071,6 +1074,14 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType, |
1071 | 1074 | super.ngDoCheck(); |
1072 | 1075 | } |
1073 | 1076 |
|
| 1077 | + public override ngOnDestroy(): void { |
| 1078 | + super.ngOnDestroy(); |
| 1079 | + for (const template of this.childDetailTemplates.values()) { |
| 1080 | + template.view.destroy(); |
| 1081 | + } |
| 1082 | + this.childDetailTemplates.clear(); |
| 1083 | + } |
| 1084 | + |
1074 | 1085 | /** |
1075 | 1086 | * @hidden @internal |
1076 | 1087 | */ |
|
0 commit comments