Skip to content

Commit c0b1b7b

Browse files
atscottalxhub
authored andcommitted
fix(router): Remove deprecated ComponentFactoryResolver from APIs (#49239)
BREAKING CHANGE: `ComponentFactoryResolver` has been removed from Router APIs. Component factories are not required to create an instance of a component dynamically. Passing a factory resolver via resolver argument is no longer needed and code can instead use `ViewContainerRef.createComponent` without the factory resolver. PR Close #49239
1 parent f07533f commit c0b1b7b

File tree

4 files changed

+9
-39
lines changed

4 files changed

+9
-39
lines changed

goldens/public-api/router/index.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { AfterContentInit } from '@angular/core';
88
import { ChangeDetectorRef } from '@angular/core';
99
import { Compiler } from '@angular/core';
10-
import { ComponentFactoryResolver } from '@angular/core';
1110
import { ComponentRef } from '@angular/core';
1211
import { ElementRef } from '@angular/core';
1312
import { EnvironmentInjector } from '@angular/core';
@@ -540,8 +539,6 @@ export class OutletContext {
540539
injector: EnvironmentInjector | null;
541540
// (undocumented)
542541
outlet: RouterOutletContract | null;
543-
// @deprecated (undocumented)
544-
resolver: ComponentFactoryResolver | null;
545542
// (undocumented)
546543
route: ActivatedRoute | null;
547544
}
@@ -874,7 +871,7 @@ export class RouterOutlet implements OnDestroy, OnInit, RouterOutletContract {
874871
// (undocumented)
875872
activateEvents: EventEmitter<any>;
876873
// (undocumented)
877-
activateWith(activatedRoute: ActivatedRoute, resolverOrInjector?: ComponentFactoryResolver | EnvironmentInjector | null): void;
874+
activateWith(activatedRoute: ActivatedRoute, environmentInjector?: EnvironmentInjector | null): void;
878875
attach(ref: ComponentRef<any>, activatedRoute: ActivatedRoute): void;
879876
attachEvents: EventEmitter<unknown>;
880877
// (undocumented)
@@ -906,8 +903,6 @@ export interface RouterOutletContract {
906903
activatedRouteData: Data;
907904
activateEvents?: EventEmitter<unknown>;
908905
activateWith(activatedRoute: ActivatedRoute, environmentInjector: EnvironmentInjector | null): void;
909-
// @deprecated
910-
activateWith(activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver | null): void;
911906
attach(ref: ComponentRef<unknown>, activatedRoute: ActivatedRoute): void;
912907
attachEvents?: EventEmitter<unknown>;
913908
component: Object | null;

packages/router/src/directives/router_outlet.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ChangeDetectorRef, ComponentFactoryResolver, ComponentRef, Directive, EnvironmentInjector, EventEmitter, inject, Injector, Input, OnDestroy, OnInit, Output, SimpleChanges, ViewContainerRef, ɵRuntimeError as RuntimeError,} from '@angular/core';
9+
import {ChangeDetectorRef, ComponentRef, Directive, EnvironmentInjector, EventEmitter, inject, Injector, Input, OnDestroy, OnInit, Output, SimpleChanges, ViewContainerRef, ɵRuntimeError as RuntimeError,} from '@angular/core';
1010

1111
import {RuntimeErrorCode} from '../errors';
1212
import {Data} from '../models';
@@ -54,13 +54,6 @@ export interface RouterOutletContract {
5454
* Called by the `Router` when the outlet should activate (create a component).
5555
*/
5656
activateWith(activatedRoute: ActivatedRoute, environmentInjector: EnvironmentInjector|null): void;
57-
/**
58-
* Called by the `Router` when the outlet should activate (create a component).
59-
*
60-
* @deprecated Passing a resolver to retrieve a component factory is not required and is
61-
* deprecated since v14.
62-
*/
63-
activateWith(activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver|null): void;
6457

6558
/**
6659
* A request to destroy the currently activated component.
@@ -311,9 +304,7 @@ export class RouterOutlet implements OnDestroy, OnInit, RouterOutletContract {
311304
}
312305
}
313306

314-
activateWith(
315-
activatedRoute: ActivatedRoute,
316-
resolverOrInjector?: ComponentFactoryResolver|EnvironmentInjector|null) {
307+
activateWith(activatedRoute: ActivatedRoute, environmentInjector?: EnvironmentInjector|null) {
317308
if (this.isActivated) {
318309
throw new RuntimeError(
319310
RuntimeErrorCode.OUTLET_ALREADY_ACTIVATED,
@@ -326,14 +317,11 @@ export class RouterOutlet implements OnDestroy, OnInit, RouterOutletContract {
326317
const childContexts = this.parentContexts.getOrCreateContext(this.name).children;
327318
const injector = new OutletInjector(activatedRoute, childContexts, location.injector);
328319

329-
if (resolverOrInjector && isComponentFactoryResolver(resolverOrInjector)) {
330-
const factory = resolverOrInjector.resolveComponentFactory(component);
331-
this.activated = location.createComponent(factory, location.length, injector);
332-
} else {
333-
const environmentInjector = resolverOrInjector ?? this.environmentInjector;
334-
this.activated = location.createComponent(
335-
component, {index: location.length, injector, environmentInjector});
336-
}
320+
this.activated = location.createComponent(component, {
321+
index: location.length,
322+
injector,
323+
environmentInjector: environmentInjector ?? this.environmentInjector
324+
});
337325
// Calling `markForCheck` to make sure we will run the change detection when the
338326
// `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
339327
this.changeDetector.markForCheck();
@@ -358,7 +346,3 @@ class OutletInjector implements Injector {
358346
return this.parent.get(token, notFoundValue);
359347
}
360348
}
361-
362-
function isComponentFactoryResolver(item: any): item is ComponentFactoryResolver {
363-
return !!item.resolveComponentFactory;
364-
}

packages/router/src/operators/activate_routes.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentFactoryResolver} from '@angular/core';
109
import {MonoTypeOperatorFunction} from 'rxjs';
1110
import {map} from 'rxjs/operators';
1211

@@ -135,7 +134,6 @@ export class ActivateRoutes {
135134
// Clear the information about the attached component on the context but keep the reference to
136135
// the outlet.
137136
context.attachRef = null;
138-
context.resolver = null;
139137
context.route = null;
140138
}
141139
}
@@ -193,10 +191,8 @@ export class ActivateRoutes {
193191
this.activateChildRoutes(futureNode, null, context.children);
194192
} else {
195193
const injector = getClosestRouteInjector(future.snapshot);
196-
const cmpFactoryResolver = injector?.get(ComponentFactoryResolver) ?? null;
197194
context.attachRef = null;
198195
context.route = future;
199-
context.resolver = cmpFactoryResolver;
200196
context.injector = injector;
201197
if (context.outlet) {
202198
// Activate the outlet when it has already been instantiated

packages/router/src/router_outlet_context.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentFactoryResolver, ComponentRef, EnvironmentInjector, Injectable} from '@angular/core';
9+
import {ComponentRef, EnvironmentInjector, Injectable} from '@angular/core';
1010

1111
import {RouterOutletContract} from './directives/router_outlet';
1212
import {ActivatedRoute} from './router_state';
@@ -20,11 +20,6 @@ import {ActivatedRoute} from './router_state';
2020
export class OutletContext {
2121
outlet: RouterOutletContract|null = null;
2222
route: ActivatedRoute|null = null;
23-
/**
24-
* @deprecated Passing a resolver to retrieve a component factory is not required and is
25-
* deprecated since v14.
26-
*/
27-
resolver: ComponentFactoryResolver|null = null;
2823
injector: EnvironmentInjector|null = null;
2924
children = new ChildrenOutletContexts();
3025
attachRef: ComponentRef<any>|null = null;

0 commit comments

Comments
 (0)