Skip to content

Commit 630c2ae

Browse files
authored
Merge branch 'master' into Form_items_as_dxi_item
2 parents dd64205 + 0e504eb commit 630c2ae

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

src/core/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export abstract class DxComponent implements INestedOptionContainer, ICollection
8888
}
8989
protected _destroyWidget() {
9090
if (this.instance) {
91-
this.instance._dispose();
91+
this.instance.element().triggerHandler({ type: 'dxremove', _angularIntegration: true });
9292
}
9393
}
9494
constructor(protected element: ElementRef, private ngZone: NgZone, templateHost: DxTemplateHost, private watcherHelper: WatcherHelper) {

src/core/template.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export class DxTemplateDirective {
4646
// =========== /WORKAROUND =============
4747
return $(childView.rootNodes)
4848
.addClass(DX_TEMPLATE_WRAPPER_CLASS)
49-
.on('dxremove', () => childView.destroy());
49+
.on('dxremove', (e) => {
50+
if (!e._angularIntegration) {
51+
childView.destroy();
52+
}
53+
});
5054
}
5155
}
5256

tests/src/ui/list.spec.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import DxList from 'devextreme/ui/list';
1616

1717
import {
18+
DxButtonModule,
1819
DxListModule,
1920
DxListComponent
2021
} from '../../../dist';
@@ -343,7 +344,7 @@ describe('DxList', () => {
343344
}));
344345

345346

346-
it('should destroy all components inside template', () => {
347+
it('should destroy angular components inside template', () => {
347348
let destroyed = false;
348349
@Component({
349350
selector: 'destroyable-component',
@@ -380,4 +381,76 @@ describe('DxList', () => {
380381

381382
expect(destroyed).toBe(true);
382383
});
384+
385+
it('should destroy devextreme components inside template', () => {
386+
@Component({
387+
selector: 'test-container-component',
388+
template: ''
389+
})
390+
class TestContainerComponent {
391+
items = [0];
392+
buttonDestroyed = false;
393+
listVisible = true;
394+
}
395+
396+
TestBed.configureTestingModule({
397+
declarations: [TestContainerComponent],
398+
imports: [DxButtonModule, DxListModule]
399+
});
400+
401+
TestBed.overrideComponent(TestContainerComponent, {
402+
set: {
403+
template: `
404+
<dx-list *ngIf="listVisible" [items]="items">
405+
<div *dxTemplate="let item of 'item'">
406+
<dx-button text="Test" (onDisposing)="buttonDestroyed = true"></dx-button>
407+
</div>
408+
</dx-list>
409+
`
410+
}
411+
});
412+
413+
let fixture = TestBed.createComponent(TestContainerComponent);
414+
fixture.detectChanges();
415+
416+
fixture.componentInstance.listVisible = false;
417+
fixture.detectChanges();
418+
419+
expect(fixture.componentInstance.buttonDestroyed).toBe(true);
420+
});
421+
422+
it('should destroy devextreme components in template root correctly', () => {
423+
@Component({
424+
selector: 'test-container-component',
425+
template: ''
426+
})
427+
class TestContainerComponent {
428+
items = [0];
429+
buttonDestroyed = false;
430+
listVisible = true;
431+
}
432+
433+
TestBed.configureTestingModule({
434+
declarations: [TestContainerComponent],
435+
imports: [DxButtonModule, DxListModule]
436+
});
437+
438+
TestBed.overrideComponent(TestContainerComponent, {
439+
set: {
440+
template: `
441+
<dx-list *ngIf="listVisible" [items]="items">
442+
<dx-button text="Test" (onDisposing)="buttonDestroyed = true" *dxTemplate="let item of 'item'"></dx-button>
443+
</dx-list>
444+
`
445+
}
446+
});
447+
448+
let fixture = TestBed.createComponent(TestContainerComponent);
449+
fixture.detectChanges();
450+
451+
fixture.componentInstance.listVisible = false;
452+
fixture.detectChanges();
453+
454+
expect(fixture.componentInstance.buttonDestroyed).toBe(true);
455+
});
383456
});

0 commit comments

Comments
 (0)