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

Function createRootTView

packages/core/src/render3/component_ref.ts:415–501  ·  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

413}
414
415function createRootTView(
416 rootSelectorOrNode: any,
417 componentDef: ComponentDef<unknown>,
418 componentBindings: Binding[] | undefined,
419 directives: (Type<unknown> | DirectiveWithBindings<unknown>)[] | undefined,
420): TView {
421 const tAttributes = rootSelectorOrNode
422 ? ['ng-version', '0.0.0-PLACEHOLDER']
423 : // Extract attributes and classes from the first selector only to match VE behavior.
424 extractAttrsAndClassesFromSelector(componentDef.selectors[0]);
425 let creationBindings: Binding[] | null = null;
426 let updateBindings: Binding[] | null = null;
427 let varsToAllocate = 0;
428
429 if (componentBindings) {
430 for (const binding of componentBindings as BindingInternal[]) {
431 varsToAllocate += binding[BINDING].requiredVars;
432
433 if (binding.create) {
434 (binding as BindingInternal).targetIdx = 0;
435 (creationBindings ??= []).push(binding);
436 }
437
438 if (binding.update) {
439 (binding as BindingInternal).targetIdx = 0;
440 (updateBindings ??= []).push(binding);
441 }
442 }
443 }
444
445 if (directives) {
446 for (let i = 0; i < directives.length; i++) {
447 const directive = directives[i];
448 if (typeof directive !== 'function') {
449 for (const binding of directive.bindings as BindingInternal[]) {
450 varsToAllocate += binding[BINDING].requiredVars;
451 const targetDirectiveIdx = i + 1;
452 if (binding.create) {
453 (binding as BindingInternal).targetIdx = targetDirectiveIdx;
454 (creationBindings ??= []).push(binding);
455 }
456
457 if (binding.update) {
458 (binding as BindingInternal).targetIdx = targetDirectiveIdx;
459 (updateBindings ??= []).push(binding);
460 }
461 }
462 }
463 }
464 }
465
466 const directivesToApply: DirectiveDef<unknown>[] = [componentDef];
467 if (directives) {
468 for (const directive of directives) {
469 const directiveType = typeof directive === 'function' ? directive : directive.type;
470 const directiveDef = ngDevMode
471 ? getDirectiveDefOrThrow(directiveType)
472 : 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