From 25f593ce2a623add0cbd4ab3bb0d4987793e4f34 Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Sun, 27 Jul 2025 15:18:09 +0200 Subject: [PATCH] refactor(common): remove`ngModuleFactory` input of `NgComponentOutlet` (#62838) This was deprecated by #44815 BREAKING CHANGE: NgModuleFactory has been removed, use NgModule instead. PR Close #62838 --- goldens/public-api/common/index.api.md | 5 +- .../public-api/common/upgrade/index.api.md | 1 - .../src/directives/ng_component_outlet.ts | 8 --- .../directives/ng_component_outlet_spec.ts | 64 ------------------- 4 files changed, 1 insertion(+), 77 deletions(-) diff --git a/goldens/public-api/common/index.api.md b/goldens/public-api/common/index.api.md index be6712ca850..9135b888825 100644 --- a/goldens/public-api/common/index.api.md +++ b/goldens/public-api/common/index.api.md @@ -17,7 +17,6 @@ import { Injector } from '@angular/core'; import { IterableDiffers } from '@angular/core'; import { KeyValueDiffers } from '@angular/core'; import { NgIterable } from '@angular/core'; -import { NgModuleFactory } from '@angular/core'; import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; @@ -503,13 +502,11 @@ export class NgComponentOutlet implements OnChanges, DoCheck, OnDestroy ngComponentOutletInputs?: Record; // (undocumented) ngComponentOutletNgModule?: Type; - // @deprecated (undocumented) - ngComponentOutletNgModuleFactory?: NgModuleFactory; ngDoCheck(): void; ngOnChanges(changes: SimpleChanges): void; ngOnDestroy(): void; // (undocumented) - static ɵdir: i0.ɵɵDirectiveDeclaration, "[ngComponentOutlet]", ["ngComponentOutlet"], { "ngComponentOutlet": { "alias": "ngComponentOutlet"; "required": false; }; "ngComponentOutletInputs": { "alias": "ngComponentOutletInputs"; "required": false; }; "ngComponentOutletInjector": { "alias": "ngComponentOutletInjector"; "required": false; }; "ngComponentOutletEnvironmentInjector": { "alias": "ngComponentOutletEnvironmentInjector"; "required": false; }; "ngComponentOutletContent": { "alias": "ngComponentOutletContent"; "required": false; }; "ngComponentOutletNgModule": { "alias": "ngComponentOutletNgModule"; "required": false; }; "ngComponentOutletNgModuleFactory": { "alias": "ngComponentOutletNgModuleFactory"; "required": false; }; }, {}, never, never, true, never>; + static ɵdir: i0.ɵɵDirectiveDeclaration, "[ngComponentOutlet]", ["ngComponentOutlet"], { "ngComponentOutlet": { "alias": "ngComponentOutlet"; "required": false; }; "ngComponentOutletInputs": { "alias": "ngComponentOutletInputs"; "required": false; }; "ngComponentOutletInjector": { "alias": "ngComponentOutletInjector"; "required": false; }; "ngComponentOutletEnvironmentInjector": { "alias": "ngComponentOutletEnvironmentInjector"; "required": false; }; "ngComponentOutletContent": { "alias": "ngComponentOutletContent"; "required": false; }; "ngComponentOutletNgModule": { "alias": "ngComponentOutletNgModule"; "required": false; }; }, {}, never, never, true, never>; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration, never>; } diff --git a/goldens/public-api/common/upgrade/index.api.md b/goldens/public-api/common/upgrade/index.api.md index 7e99f9da04d..67ac0b77915 100644 --- a/goldens/public-api/common/upgrade/index.api.md +++ b/goldens/public-api/common/upgrade/index.api.md @@ -15,7 +15,6 @@ import { IterableDiffers } from '@angular/core'; import { KeyValueDiffers } from '@angular/core'; import { ModuleWithProviders } from '@angular/core'; import { NgIterable } from '@angular/core'; -import { NgModuleFactory } from '@angular/core'; import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; diff --git a/packages/common/src/directives/ng_component_outlet.ts b/packages/common/src/directives/ng_component_outlet.ts index f91b60e2785..dce54520141 100644 --- a/packages/common/src/directives/ng_component_outlet.ts +++ b/packages/common/src/directives/ng_component_outlet.ts @@ -111,10 +111,6 @@ export class NgComponentOutlet implements OnChanges, DoCheck, OnDestroy @Input() ngComponentOutletContent?: any[][]; @Input() ngComponentOutletNgModule?: Type; - /** - * @deprecated This input is deprecated, use `ngComponentOutletNgModule` instead. - */ - @Input() ngComponentOutletNgModuleFactory?: NgModuleFactory; private _componentRef: ComponentRef | undefined; private _moduleRef: NgModuleRef | undefined; @@ -177,10 +173,6 @@ export class NgComponentOutlet implements OnChanges, DoCheck, OnDestroy this.ngComponentOutletNgModule, getParentInjector(injector), ); - } else if (this.ngComponentOutletNgModuleFactory) { - this._moduleRef = this.ngComponentOutletNgModuleFactory.create( - getParentInjector(injector), - ); } else { this._moduleRef = undefined; } diff --git a/packages/common/test/directives/ng_component_outlet_spec.ts b/packages/common/test/directives/ng_component_outlet_spec.ts index 8c12ec1c464..36531ad31f1 100644 --- a/packages/common/test/directives/ng_component_outlet_spec.ts +++ b/packages/common/test/directives/ng_component_outlet_spec.ts @@ -187,20 +187,6 @@ describe('insert/remove', () => { expect(fixture.nativeElement).toHaveText('projected foo'); })); - it('should resolve components from other modules, if supplied as an NgModuleFactory', waitForAsync(() => { - const compiler = TestBed.inject(Compiler); - let fixture = TestBed.createComponent(TestComponent); - - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); - - fixture.componentInstance.ngModuleFactory = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('baz'); - })); - it('should resolve components from other modules, if supplied as an NgModule class reference', waitForAsync(() => { let fixture = TestBed.createComponent(TestComponent); @@ -214,21 +200,6 @@ describe('insert/remove', () => { expect(fixture.nativeElement).toHaveText('baz'); })); - it('should clean up moduleRef, if supplied as an NgModuleFactory', waitForAsync(() => { - const compiler = TestBed.inject(Compiler); - const fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.ngModuleFactory = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); - - const moduleRef = fixture.componentInstance.ngComponentOutlet?.['_moduleRef']!; - spyOn(moduleRef, 'destroy').and.callThrough(); - - expect(moduleRef.destroy).not.toHaveBeenCalled(); - fixture.destroy(); - expect(moduleRef.destroy).toHaveBeenCalled(); - })); - it('should clean up moduleRef, if supplied as an NgModule class reference', waitForAsync(() => { const fixture = TestBed.createComponent(TestComponent); fixture.componentInstance.ngModule = TestModule2; @@ -243,39 +214,6 @@ describe('insert/remove', () => { expect(moduleRef.destroy).toHaveBeenCalled(); })); - it("should not re-create moduleRef when it didn't actually change", waitForAsync(() => { - const compiler = TestBed.inject(Compiler); - const fixture = TestBed.createComponent(TestComponent); - - fixture.componentInstance.ngModuleFactory = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('baz'); - const moduleRef = fixture.componentInstance.ngComponentOutlet?.['_moduleRef']; - - fixture.componentInstance.currentComponent = Module2InjectedComponent2; - fixture.detectChanges(); - - expect(fixture.nativeElement).toHaveText('baz2'); - expect(moduleRef).toBe(fixture.componentInstance.ngComponentOutlet?.['_moduleRef']); - })); - - it('should re-create moduleRef when changed (NgModuleFactory)', waitForAsync(() => { - const compiler = TestBed.inject(Compiler); - const fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.ngModuleFactory = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); - - expect(fixture.nativeElement).toHaveText('baz'); - - fixture.componentInstance.ngModuleFactory = compiler.compileModuleSync(TestModule3); - fixture.componentInstance.currentComponent = Module3InjectedComponent; - fixture.detectChanges(); - - expect(fixture.nativeElement).toHaveText('bat'); - })); - it('should re-create moduleRef when changed (NgModule class reference)', waitForAsync(() => { const fixture = TestBed.createComponent(TestComponent); fixture.componentInstance.ngModule = TestModule2; @@ -438,7 +376,6 @@ const TEST_CMP_TEMPLATE = ``; @Component({ selector: 'test-cmp', @@ -452,7 +389,6 @@ class TestComponent { inputs?: Record; projectables?: any[][]; ngModule?: Type; - ngModuleFactory?: NgModuleFactory; get cmpRef(): ComponentRef | undefined { return this.ngComponentOutlet?.['_componentRef'];