File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 22 Component ,
33 ComponentFactoryResolver ,
44 NgModule ,
5+ OnDestroy ,
56 Optional ,
67 ViewContainerRef ,
78} from '@angular/core' ;
@@ -13,23 +14,29 @@ import { MockBuilder, ngMocks } from 'ng-mocks';
1314 selector : 'parent' ,
1415 template : '<div #parent>parent</div>' ,
1516} )
16- class ParentComponent {
17+ class ParentComponent implements OnDestroy {
18+ private readonly vcr : ViewContainerRef ;
19+
1720 public constructor (
1821 viewContainerRef : ViewContainerRef ,
1922 @Optional ( ) componentFactoryResolver : ComponentFactoryResolver ,
2023 ) {
21- const vcr : any = viewContainerRef ;
24+ this . vcr = viewContainerRef ;
2225
2326 try {
24- vcr . createComponent ( ChildComponent ) ;
25- } catch ( e ) {
27+ ( this . vcr as any ) . createComponent ( ChildComponent ) ;
28+ } catch {
2629 const factory =
2730 componentFactoryResolver . resolveComponentFactory (
2831 ChildComponent ,
2932 ) ;
30- vcr . createComponent ( factory ) ;
33+ ( this . vcr as any ) . createComponent ( factory ) ;
3134 }
3235 }
36+
37+ public ngOnDestroy ( ) : void {
38+ this . vcr . clear ( ) ;
39+ }
3340}
3441
3542@Component ( {
You can’t perform that action at this time.
0 commit comments