MCPcopy Index your code
hub / github.com/angular/angular / setupInitialInputs

Function setupInitialInputs

packages/core/src/render3/view/directives.ts:366–429  ·  view source on GitHub ↗

* Sets up the initialInputData for a node and stores it in the template's static storage * so subsequent template invocations don't have to recalculate it. * * initialInputData is an array containing values that need to be set as input properties * for directives on this node, but only once on c

(tNode: TNode, directiveIndex: number, isHostDirective: boolean)

Source from the content-addressed store, hash-verified

364 * @param directiveIndex Index of the directive that is currently being processed.
365 */
366function setupInitialInputs(tNode: TNode, directiveIndex: number, isHostDirective: boolean): void {
367 const {attrs, inputs, hostDirectiveInputs} = tNode;
368
369 if (
370 attrs === null ||
371 (!isHostDirective && inputs === null) ||
372 (isHostDirective && hostDirectiveInputs === null) ||
373 // Do not use unbound attributes as inputs to structural directives, since structural
374 // directive inputs can only be set using microsyntax (e.g. `<div *dir="exp">`).
375 isInlineTemplate(tNode)
376 ) {
377 tNode.initialInputs ??= [];
378 tNode.initialInputs.push(null);
379 return;
380 }
381
382 let inputsToStore: InitialInputs | null = null;
383 let i = 0;
384 while (i < attrs.length) {
385 const attrName = attrs[i];
386 if (attrName === AttributeMarker.NamespaceURI) {
387 // We do not allow inputs on namespaced attributes.
388 i += 4;
389 continue;
390 } else if (attrName === AttributeMarker.ProjectAs) {
391 // Skip over the `ngProjectAs` value.
392 i += 2;
393 continue;
394 } else if (typeof attrName === 'number') {
395 // If we hit any other attribute markers, we're done anyway. None of those are valid inputs.
396 break;
397 }
398
399 if (!isHostDirective && inputs!.hasOwnProperty(attrName as string)) {
400 // Find the input's public name from the input store. Note that we can be found easier
401 // through the directive def, but we want to do it using the inputs store so that it can
402 // account for host directive aliases.
403 const inputConfig = inputs![attrName as string];
404
405 for (const index of inputConfig) {
406 if (index === directiveIndex) {
407 inputsToStore ??= [];
408 inputsToStore.push(attrName as string, attrs[i + 1] as string);
409 // A directive can't have multiple inputs with the same name so we can break here.
410 break;
411 }
412 }
413 } else if (isHostDirective && hostDirectiveInputs!.hasOwnProperty(attrName as string)) {
414 const config = hostDirectiveInputs![attrName as string];
415 for (let j = 0; j < config.length; j += 2) {
416 if (config[j] === directiveIndex) {
417 inputsToStore ??= [];
418 inputsToStore.push(config[j + 1] as string, attrs[i + 1] as string);
419 break;
420 }
421 }
422 }
423

Callers 1

Calls 2

isInlineTemplateFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…