Skip to content

Commit b1f5181

Browse files
JeanMecheatscott
authored andcommitted
refactor(core): remove ComponentFactoryResolver & ComponentFactory from the api surface""
Those APIs date back to pre-ivy times and are long deprecated. BREAKING CHANGE: `ComponentFactoryResolver` and `ComponentFactory` are no longer available. Pass the component class directly to APIs that previously required a factory, such as `ViewContainerRef.createComponent` or use the standalone `createComponent` function.
1 parent ab061a7 commit b1f5181

File tree

21 files changed

+95
-364
lines changed

21 files changed

+95
-364
lines changed

goldens/public-api/core/index.api.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ export class ApplicationRef {
134134
constructor();
135135
attachView(viewRef: ViewRef): void;
136136
bootstrap<C>(component: Type<C>, rootSelectorOrNode?: string | any): ComponentRef<C>;
137-
// @deprecated
138-
bootstrap<C>(componentFactory: ComponentFactory<C>, rootSelectorOrNode?: string | any): ComponentRef<C>;
139137
readonly components: ComponentRef<any>[];
140138
readonly componentTypes: Type<any>[];
141139
destroy(): void;
@@ -293,31 +291,6 @@ export interface ComponentDecorator {
293291
new (obj: Component): Component;
294292
}
295293

296-
// @public @deprecated
297-
export abstract class ComponentFactory<C> {
298-
abstract get componentType(): Type<any>;
299-
abstract create(injector: Injector, projectableNodes?: any[][], rootSelectorOrNode?: string | any, environmentInjector?: EnvironmentInjector | NgModuleRef<any>, directives?: (Type<unknown> | DirectiveWithBindings<unknown>)[], bindings?: Binding[]): ComponentRef<C>;
300-
abstract get inputs(): {
301-
propName: string;
302-
templateName: string;
303-
transform?: (value: any) => any;
304-
isSignal: boolean;
305-
}[];
306-
abstract get ngContentSelectors(): string[];
307-
abstract get outputs(): {
308-
propName: string;
309-
templateName: string;
310-
}[];
311-
abstract get selector(): string;
312-
}
313-
314-
// @public @deprecated
315-
export abstract class ComponentFactoryResolver {
316-
// (undocumented)
317-
static NULL: ComponentFactoryResolver;
318-
abstract resolveComponentFactory<T>(component: Type<T>): ComponentFactory<T>;
319-
}
320-
321294
// @public
322295
export interface ComponentMirror<C> {
323296
get inputs(): ReadonlyArray<{
@@ -2072,8 +2045,6 @@ export abstract class ViewContainerRef {
20722045
directives?: (Type<unknown> | DirectiveWithBindings<unknown>)[];
20732046
bindings?: Binding[];
20742047
}): ComponentRef<C>;
2075-
// @deprecated
2076-
abstract createComponent<C>(componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, projectableNodes?: any[][], environmentInjector?: EnvironmentInjector | NgModuleRef<any>, directives?: (Type<unknown> | DirectiveWithBindings<unknown>)[], bindings?: Binding[]): ComponentRef<C>;
20772048
abstract createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, options?: {
20782049
index?: number;
20792050
injector?: Injector;

packages/core/src/application/application_ref.ts

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import '../util/ng_hmr_mode';
1010
import '../util/ng_jit_mode';
1111
import '../util/ng_server_mode';
1212

13+
import {type Observable, Subject, type Subscription} from 'rxjs';
14+
import {map} from 'rxjs/operators';
1315
import {
14-
setActiveConsumer,
1516
getActiveConsumer,
17+
setActiveConsumer,
1618
setThrowInvalidWriteToSignalError,
1719
} from '../../primitives/signals';
18-
import {type Observable, Subject, type Subscription} from 'rxjs';
19-
import {map} from 'rxjs/operators';
2020

2121
import {ZONELESS_ENABLED} from '../change_detection/scheduling/zoneless_scheduling';
2222
import {Console} from '../console';
@@ -25,8 +25,8 @@ import {Injectable} from '../di/injectable';
2525
import {InjectionToken} from '../di/injection_token';
2626
import {Injector} from '../di/injector';
2727
import {EnvironmentInjector, type R3Injector} from '../di/r3_injector';
28-
import {formatRuntimeError, RuntimeError, RuntimeErrorCode} from '../errors';
2928
import {INTERNAL_APPLICATION_ERROR_HANDLER} from '../error_handler';
29+
import {formatRuntimeError, RuntimeError, RuntimeErrorCode} from '../errors';
3030
import {Type} from '../interface/type';
3131
import {ComponentFactory, ComponentRef} from '../linker/component_factory';
3232
import {ComponentFactoryResolver} from '../linker/component_factory_resolver';
@@ -44,10 +44,10 @@ import {ViewRef as InternalViewRef} from '../render3/view_ref';
4444
import {TESTABILITY} from '../testability/testability';
4545
import {NgZone} from '../zone/ng_zone';
4646

47-
import {profiler} from '../render3/profiler';
4847
import {ProfilerEvent} from '../../primitives/devtools';
49-
import {EffectScheduler} from '../render3/reactivity/root_effect_scheduler';
48+
import {profiler} from '../render3/profiler';
5049
import {isReactiveLViewConsumer} from '../render3/reactive_lview_consumer';
50+
import {EffectScheduler} from '../render3/reactivity/root_effect_scheduler';
5151
import {ApplicationInitStatus} from './application_init';
5252
import {TracingAction, TracingService, TracingSnapshot} from './tracing';
5353

@@ -441,61 +441,13 @@ export class ApplicationRef {
441441
* While in this example, we are providing reference to a DOM node.
442442
*
443443
* {@example core/ts/platform/platform.ts region='domNode'}
444-
*
445-
* @deprecated Passing Component factories as the `Application.bootstrap` function argument is
446-
* deprecated. Pass Component Types instead.
447444
*/
448-
bootstrap<C>(
449-
componentFactory: ComponentFactory<C>,
450-
rootSelectorOrNode?: string | any,
451-
): ComponentRef<C>;
452-
453-
/**
454-
* Bootstrap a component onto the element identified by its selector or, optionally, to a
455-
* specified element.
456-
*
457-
* @usageNotes
458-
* ### Bootstrap process
459-
*
460-
* When bootstrapping a component, Angular mounts it onto a target DOM element
461-
* and kicks off automatic change detection. The target DOM element can be
462-
* provided using the `rootSelectorOrNode` argument.
463-
*
464-
* If the target DOM element is not provided, Angular tries to find one on a page
465-
* using the `selector` of the component that is being bootstrapped
466-
* (first matched element is used).
467-
*
468-
* ### Example
469-
*
470-
* Generally, we define the component to bootstrap in the `bootstrap` array of `NgModule`,
471-
* but it requires us to know the component while writing the application code.
472-
*
473-
* Imagine a situation where we have to wait for an API call to decide about the component to
474-
* bootstrap. We can use the `ngDoBootstrap` hook of the `NgModule` and call this method to
475-
* dynamically bootstrap a component.
476-
*
477-
* {@example core/ts/platform/platform.ts region='componentSelector'}
478-
*
479-
* Optionally, a component can be mounted onto a DOM element that does not match the
480-
* selector of the bootstrapped component.
481-
*
482-
* In the following example, we are providing a CSS selector to match the target element.
483-
*
484-
* {@example core/ts/platform/platform.ts region='cssSelector'}
485-
*
486-
* While in this example, we are providing reference to a DOM node.
487-
*
488-
* {@example core/ts/platform/platform.ts region='domNode'}
489-
*/
490-
bootstrap<C>(
491-
componentOrFactory: ComponentFactory<C> | Type<C>,
492-
rootSelectorOrNode?: string | any,
493-
): ComponentRef<C> {
494-
return this.bootstrapImpl(componentOrFactory, rootSelectorOrNode);
445+
bootstrap<C>(component: Type<C>, rootSelectorOrNode?: string | any): ComponentRef<C> {
446+
return this.bootstrapImpl(component, rootSelectorOrNode);
495447
}
496448

497449
private bootstrapImpl<C>(
498-
componentOrFactory: ComponentFactory<C> | Type<C>,
450+
component: Type<C>,
499451
rootSelectorOrNode?: string | any,
500452
injector: Injector = Injector.NULL,
501453
): ComponentRef<C> {
@@ -504,13 +456,12 @@ export class ApplicationRef {
504456
profiler(ProfilerEvent.BootstrapComponentStart);
505457

506458
(typeof ngDevMode === 'undefined' || ngDevMode) && warnIfDestroyed(this._destroyed);
507-
const isComponentFactory = componentOrFactory instanceof ComponentFactory;
508459
const initStatus = this._injector.get(ApplicationInitStatus);
509460

510461
if (!initStatus.done) {
511462
let errorMessage = '';
512463
if (typeof ngDevMode === 'undefined' || ngDevMode) {
513-
const standalone = !isComponentFactory && isStandalone(componentOrFactory);
464+
const standalone = isStandalone(component);
514465
errorMessage =
515466
'Cannot bootstrap as there are still asynchronous initializers running.' +
516467
(standalone
@@ -520,13 +471,8 @@ export class ApplicationRef {
520471
throw new RuntimeError(RuntimeErrorCode.ASYNC_INITIALIZERS_STILL_RUNNING, errorMessage);
521472
}
522473

523-
let componentFactory: ComponentFactory<C>;
524-
if (isComponentFactory) {
525-
componentFactory = componentOrFactory;
526-
} else {
527-
const resolver = this._injector.get(ComponentFactoryResolver);
528-
componentFactory = resolver.resolveComponentFactory(componentOrFactory)!;
529-
}
474+
const resolver = this._injector.get(ComponentFactoryResolver);
475+
const componentFactory = resolver.resolveComponentFactory(component)!;
530476
this.componentTypes.push(componentFactory.componentType);
531477

532478
// Create a factory associated with the current module if it's not bound to some other

packages/core/src/linker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export {
1414
CompilerOptions,
1515
ModuleWithComponentFactories,
1616
} from './linker/compiler';
17-
export {ComponentFactory, ComponentRef} from './linker/component_factory';
18-
export {ComponentFactoryResolver} from './linker/component_factory_resolver';
17+
export {ComponentRef, ComponentFactory as ɵComponentFactory} from './linker/component_factory';
18+
export {ComponentFactoryResolver as ɵComponentFactoryResolver} from './linker/component_factory_resolver';
1919
export {DestroyRef} from './linker/destroy_ref';
2020
export {ElementRef} from './linker/element_ref';
2121
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';

packages/core/src/linker/component_factory.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ export abstract class ComponentRef<C> {
8585
* Base class for a factory that can create a component dynamically.
8686
* Instantiate a factory for a given type of component with `resolveComponentFactory()`.
8787
* Use the resulting `ComponentFactory.create()` method to create a component of that type.
88-
*
89-
* @publicApi
90-
*
91-
* @deprecated Angular no longer requires Component factories. Please use other APIs where
92-
* Component class can be used directly.
9388
*/
9489
export abstract class ComponentFactory<C> {
9590
/**

packages/core/src/linker/component_factory_resolver.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class _NullComponentFactoryResolver implements ComponentFactoryResolver {
3232
* Note: since v13, dynamic component creation via
3333
* [`ViewContainerRef.createComponent`](api/core/ViewContainerRef#createComponent)
3434
* does **not** require resolving component factory: component class can be used directly.
35-
*
36-
* @publicApi
37-
*
38-
* @deprecated Angular no longer requires Component factories. Please use other APIs where
39-
* Component class can be used directly.
4035
*/
4136
export abstract class ComponentFactoryResolver {
4237
static NULL: ComponentFactoryResolver = /* @__PURE__ */ new _NullComponentFactoryResolver();

0 commit comments

Comments
 (0)