MCPcopy
hub / github.com/angular/angular / setDirectiveInput

Function setDirectiveInput

packages/core/src/render3/instructions/shared.ts:774–829  ·  view source on GitHub ↗
(
  tNode: TNode,
  tView: TView,
  lView: LView,
  target: DirectiveDef<unknown>,
  publicName: string,
  value: unknown,
)

Source from the content-addressed store, hash-verified

772 * @param value Value to set.
773 */
774export function setDirectiveInput(
775 tNode: TNode,
776 tView: TView,
777 lView: LView,
778 target: DirectiveDef<unknown>,
779 publicName: string,
780 value: unknown,
781): boolean {
782 let hostIndex: number | null = null;
783 let hostDirectivesStart: number | null = null;
784 let hostDirectivesEnd: number | null = null;
785 let hasSet = false;
786
787 if (ngDevMode && !tNode.directiveToIndex?.has(target.type)) {
788 throw new Error(`Node does not have a directive with type ${target.type.name}`);
789 }
790
791 const data = tNode.directiveToIndex!.get(target.type)!;
792
793 if (typeof data === 'number') {
794 hostIndex = data;
795 } else {
796 [hostIndex, hostDirectivesStart, hostDirectivesEnd] = data;
797 }
798
799 if (
800 hostDirectivesStart !== null &&
801 hostDirectivesEnd !== null &&
802 tNode.hostDirectiveInputs?.hasOwnProperty(publicName)
803 ) {
804 const hostDirectiveInputs = tNode.hostDirectiveInputs[publicName];
805
806 for (let i = 0; i < hostDirectiveInputs.length; i += 2) {
807 const index = hostDirectiveInputs[i] as number;
808
809 if (index >= hostDirectivesStart && index <= hostDirectivesEnd) {
810 ngDevMode && assertIndexInRange(lView, index);
811 const def = tView.data[index] as DirectiveDef<unknown>;
812 const hostDirectivePublicName = hostDirectiveInputs[i + 1] as string;
813 writeToDirectiveInput(def, lView[index], hostDirectivePublicName, value);
814 hasSet = true;
815 } else if (index > hostDirectivesEnd) {
816 // Directives here are in ascending order so we can stop looking once we're past the range.
817 break;
818 }
819 }
820 }
821
822 if (hostIndex !== null && target.inputs.hasOwnProperty(publicName)) {
823 ngDevMode && assertIndexInRange(lView, hostIndex);
824 writeToDirectiveInput(target, lView[hostIndex], publicName, value);
825 hasSet = true;
826 }
827
828 return hasSet;
829}

Callers 2

inputBindingUpdateFunction · 0.90

Calls 4

assertIndexInRangeFunction · 0.90
writeToDirectiveInputFunction · 0.90
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…