MCPcopy
hub / github.com/angular/angular / ɵɵdefineComponent

Function ɵɵdefineComponent

packages/core/src/render3/definition.ts:336–385  ·  view source on GitHub ↗
(
  componentDefinition: ComponentDefinition<T>,
)

Source from the content-addressed store, hash-verified

334 * @codeGenApi
335 */
336export function ɵɵdefineComponent<T>(
337 componentDefinition: ComponentDefinition<T>,
338): ComponentDef<any> {
339 return noSideEffects(() => {
340 // Initialize ngDevMode. This must be the first statement in ɵɵdefineComponent.
341 // See the `initNgDevMode` docstring for more information.
342 (typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode();
343
344 const baseDef = getNgDirectiveDef(componentDefinition as DirectiveDefinition<T>);
345 const def: Writable<ComponentDef<T>> = {
346 ...baseDef,
347 decls: componentDefinition.decls,
348 vars: componentDefinition.vars,
349 template: componentDefinition.template,
350 consts: componentDefinition.consts || null,
351 ngContentSelectors: componentDefinition.ngContentSelectors,
352 onPush: componentDefinition.changeDetection !== ChangeDetectionStrategy.Eager,
353 directiveDefs: null!, // assigned in noSideEffects
354 pipeDefs: null!, // assigned in noSideEffects
355 dependencies: (baseDef.standalone && componentDefinition.dependencies) || null,
356 getStandaloneInjector: baseDef.standalone
357 ? (parentInjector: EnvironmentInjector) => {
358 return parentInjector.get(StandaloneService).getOrCreateStandaloneInjector(def);
359 }
360 : null,
361 getExternalStyles: null,
362 signals: componentDefinition.signals ?? false,
363 data: componentDefinition.data || {},
364 encapsulation: componentDefinition.encapsulation || ViewEncapsulation.Emulated,
365 styles: componentDefinition.styles || EMPTY_ARRAY,
366 _: null,
367 schemas: componentDefinition.schemas || null,
368 tView: null,
369 id: '',
370 };
371
372 // TODO: Do we still need/want this ?
373 if (baseDef.standalone) {
374 performanceMarkFeature('NgStandalone');
375 }
376
377 initFeatures(def);
378 const dependencies = componentDefinition.dependencies;
379 def.directiveDefs = extractDefListOrFactory(dependencies, extractDirectiveDef);
380 def.pipeDefs = extractDefListOrFactory(dependencies, getPipeDef);
381 def.id = getComponentId(def);
382
383 return def;
384 });
385}
386
387export function extractDirectiveDef(type: Type<any>): DirectiveDef<any> | ComponentDef<any> | null {
388 return getComponentDef(type) || getDirectiveDef(type);

Callers 3

CompClass · 0.90
CompClass · 0.90
CompClass · 0.90

Calls 9

noSideEffectsFunction · 0.90
initNgDevModeFunction · 0.90
performanceMarkFeatureFunction · 0.90
getNgDirectiveDefFunction · 0.85
initFeaturesFunction · 0.85
extractDefListOrFactoryFunction · 0.85
getComponentIdFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…