Skip to content

Commit 54bf818

Browse files
MKirovaMKirova
authored andcommitted
fix(elements): Do not destroy elements inside tmpl wrapper on detach.
1 parent 1fb2e40 commit 54bf818

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

projects/igniteui-angular-elements/src/app/custom-strategy.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
233233
}
234234
value = this.templateWrapper.addTemplate(value);
235235
// TODO: discard oldValue
236+
237+
// check template for any angular-element components
238+
this.templateWrapper.templateRendered.subscribe((element) => {
239+
const igComponents = this.config.flatMap(x => [
240+
x.selector,
241+
reflectComponentType(x.component).selector
242+
]).join(',');
243+
const children = element.querySelectorAll(igComponents);
244+
children?.forEach((c) => {
245+
c.ngElementStrategy.angularParent = componentRef;
246+
});
247+
});
236248
}
237249
if (componentRef && componentConfig?.boolProps?.includes(property)) {
238250
// bool coerce:

projects/igniteui-angular-elements/src/app/wrapper/wrapper.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Component, QueryList, TemplateRef, ViewChildren } from '@angular/core';
1+
import { ChangeDetectorRef, Component, EventEmitter, QueryList, TemplateRef, ViewChildren } from '@angular/core';
22
import { TemplateRefWrapper } from './template-ref-wrapper';
33

44
import { render, TemplateResult } from 'lit-html';
@@ -14,6 +14,7 @@ type TemplateFunction = (arg: any) => TemplateResult;
1414
export class TemplateWrapperComponent {
1515

1616
public templateFunctions: TemplateFunction[] = [];
17+
public templateRendered = new EventEmitter<any>();
1718

1819
/**
1920
* All template refs
@@ -27,6 +28,7 @@ export class TemplateWrapperComponent {
2728

2829
public litRender(container: HTMLElement, templateFunc: (arg: any) => TemplateResult, arg: any) {
2930
render(templateFunc(arg), container);
31+
this.templateRendered.emit(container);
3032
}
3133

3234
public addTemplate(templateFunc: TemplateFunction): TemplateRef<any> {

projects/igniteui-angular-elements/src/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
195195
<igc-combo ${ref(focusCallback)} style="width:100%; height:100%" .data=${northwindProducts} value-key="ProductName" @igcChange=${(e) => ctx.cell.editValue = e.detail.newValue} single-select>
196196
</igc-combo>
197197
`;
198-
grid1.detailTemplate = (ctx) => html`<div><span class="categoryStyle">Stock: ${ctx.implicit.InStock}</span></div>`;
198+
grid1.detailTemplate = (ctx) => {
199+
return html`<div>
200+
<igc-grid auto-generate="true"></igc-grid>
201+
</div>`;
202+
}
199203

200204
grid2.querySelector('igc-column[field="ProductName"]').inlineEditorTemplate = (ctx) =>
201205
html`

0 commit comments

Comments
 (0)