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

Function createRootTView

packages/core/src/render3/component_ref.ts:432–518  ·  view source on GitHub ↗
(
  rootSelectorOrNode: any,
  componentDef: ComponentDef<unknown>,
  componentBindings: Binding[] | undefined,
  directives: (Type<unknown> | DirectiveWithBindings<unknown>)[] | undefined,
)

Source from the content-addressed store, hash-verified

430}
431
432function createRootTView(
433 rootSelectorOrNode: any,
434 componentDef: ComponentDef<unknown>,
435 componentBindings: Binding[] | undefined,
436 directives: (Type<unknown> | DirectiveWithBindings<unknown>)[] | undefined,
437): TView {
438 const tAttributes = rootSelectorOrNode
439 ? ['ng-version', '0.0.0-PLACEHOLDER']
440 : // Extract attributes and classes from the first selector only to match VE behavior.
441 extractAttrsAndClassesFromSelector(componentDef.selectors[0]);
442 let creationBindings: Binding[] | null = null;
443 let updateBindings: Binding[] | null = null;
444 let varsToAllocate = 0;
445
446 if (componentBindings) {
447 for (const binding of componentBindings as BindingInternal[]) {
448 varsToAllocate += binding[BINDING].requiredVars;
449
450 if (binding.create) {
451 (binding as BindingInternal).targetIdx = 0;
452 (creationBindings ??= []).push(binding);
453 }
454
455 if (binding.update) {
456 (binding as BindingInternal).targetIdx = 0;
457 (updateBindings ??= []).push(binding);
458 }
459 }
460 }
461
462 if (directives) {
463 for (let i = 0; i < directives.length; i++) {
464 const directive = directives[i];
465 if (typeof directive !== 'function') {
466 for (const binding of directive.bindings as BindingInternal[]) {
467 varsToAllocate += binding[BINDING].requiredVars;
468 const targetDirectiveIdx = i + 1;
469 if (binding.create) {
470 (binding as BindingInternal).targetIdx = targetDirectiveIdx;
471 (creationBindings ??= []).push(binding);
472 }
473
474 if (binding.update) {
475 (binding as BindingInternal).targetIdx = targetDirectiveIdx;
476 (updateBindings ??= []).push(binding);
477 }
478 }
479 }
480 }
481 }
482
483 const directivesToApply: DirectiveDef<unknown>[] = [componentDef];
484 if (directives) {
485 for (const directive of directives) {
486 const directiveType = typeof directive === 'function' ? directive : directive.type;
487 const directiveDef = ngDevMode
488 ? getDirectiveDefOrThrow(directiveType)
489 : getDirectiveDef(directiveType)!;

Callers 1

createComponentRefMethod · 0.85

Calls 7

getDirectiveDefOrThrowFunction · 0.90
getDirectiveDefFunction · 0.90
stringifyForErrorFunction · 0.90
createTViewFunction · 0.90
getRootTViewTemplateFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected