MCPcopy Create free account
hub / github.com/angular/angular / ɵɵdefineComponent

Function ɵɵdefineComponent

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

Source from the content-addressed store, hash-verified

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

Callers 4

CompClass · 0.90
CompClass · 0.90
CompClass · 0.90
DirectiveTestHostClass · 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