MCPcopy Create free account
hub / github.com/angular/angular / createComponent

Function createComponent

packages/core/src/render3/component.ts:89–117  ·  view source on GitHub ↗
(
  component: Type<C>,
  options: {
    environmentInjector: EnvironmentInjector;
    hostElement?: Element;
    elementInjector?: Injector;
    projectableNodes?: Node[][];
    directives?: (Type<unknown> | DirectiveWithBindings<unknown>)[];
    bindings?: Binding[];
    onError?: (error: Error, details: ErrorDetails) => void;
  },
)

Source from the content-addressed store, hash-verified

87 * @publicApi
88 */
89export function createComponent<C>(
90 component: Type<C>,
91 options: {
92 environmentInjector: EnvironmentInjector;
93 hostElement?: Element;
94 elementInjector?: Injector;
95 projectableNodes?: Node[][];
96 directives?: (Type<unknown> | DirectiveWithBindings<unknown>)[];
97 bindings?: Binding[];
98 onError?: (error: Error, details: ErrorDetails) => void;
99 },
100): ComponentRef<C> {
101 ngDevMode && assertComponentDef(component);
102 const componentDef = getComponentDef(component)!;
103 const elementInjector = options.elementInjector || getNullInjector();
104 const factory = new ComponentFactory<C>(componentDef);
105 const componentRef = factory.create(
106 elementInjector,
107 options.projectableNodes,
108 options.hostElement,
109 options.environmentInjector,
110 options.directives,
111 options.bindings,
112 );
113 if (options.onError) {
114 (componentRef.hostView as R3ViewRef<any>)._lView![ON_ERROR] = options.onError;
115 }
116 return componentRef;
117}
118
119/**
120 * An interface that describes the subset of component metadata

Callers 11

ngAfterViewInitMethod · 0.90
ngAfterViewInitMethod · 0.90
createComponentMethod · 0.90
initializeComponentMethod · 0.90
createDomFunction · 0.90
showAsComponentMethod · 0.90
renderComponentMethod · 0.90

Calls 4

createMethod · 0.95
assertComponentDefFunction · 0.90
getComponentDefFunction · 0.90
getNullInjectorFunction · 0.90

Tested by

no test coverage detected