mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(common): removengModuleFactory input of NgComponentOutlet (#62838)
This was deprecated by #44815 BREAKING CHANGE: NgModuleFactory has been removed, use NgModule instead. PR Close #62838
This commit is contained in:
committed by
Jessica Janiuk
parent
4dfa6f1942
commit
25f593ce2a
@@ -111,10 +111,6 @@ export class NgComponentOutlet<T = any> implements OnChanges, DoCheck, OnDestroy
|
||||
@Input() ngComponentOutletContent?: any[][];
|
||||
|
||||
@Input() ngComponentOutletNgModule?: Type<any>;
|
||||
/**
|
||||
* @deprecated This input is deprecated, use `ngComponentOutletNgModule` instead.
|
||||
*/
|
||||
@Input() ngComponentOutletNgModuleFactory?: NgModuleFactory<any>;
|
||||
|
||||
private _componentRef: ComponentRef<T> | undefined;
|
||||
private _moduleRef: NgModuleRef<any> | undefined;
|
||||
@@ -177,10 +173,6 @@ export class NgComponentOutlet<T = any> implements OnChanges, DoCheck, OnDestroy
|
||||
this.ngComponentOutletNgModule,
|
||||
getParentInjector(injector),
|
||||
);
|
||||
} else if (this.ngComponentOutletNgModuleFactory) {
|
||||
this._moduleRef = this.ngComponentOutletNgModuleFactory.create(
|
||||
getParentInjector(injector),
|
||||
);
|
||||
} else {
|
||||
this._moduleRef = undefined;
|
||||
}
|
||||
|
||||
@@ -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 = `<ng-template *ngComponentOutlet="
|
||||
inputs: inputs;
|
||||
content: projectables;
|
||||
ngModule: ngModule;
|
||||
ngModuleFactory: ngModuleFactory;
|
||||
"></ng-template>`;
|
||||
@Component({
|
||||
selector: 'test-cmp',
|
||||
@@ -452,7 +389,6 @@ class TestComponent {
|
||||
inputs?: Record<string, unknown>;
|
||||
projectables?: any[][];
|
||||
ngModule?: Type<unknown>;
|
||||
ngModuleFactory?: NgModuleFactory<unknown>;
|
||||
|
||||
get cmpRef(): ComponentRef<any> | undefined {
|
||||
return this.ngComponentOutlet?.['_componentRef'];
|
||||
|
||||
Reference in New Issue
Block a user