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

Function setDirectiveInput

packages/core/src/render3/instructions/shared.ts:774–830  ·  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 &&
803 Object.hasOwn(tNode.hostDirectiveInputs, publicName)
804 ) {
805 const hostDirectiveInputs = tNode.hostDirectiveInputs[publicName];
806
807 for (let i = 0; i < hostDirectiveInputs.length; i += 2) {
808 const index = hostDirectiveInputs[i] as number;
809
810 if (index >= hostDirectivesStart && index <= hostDirectivesEnd) {
811 ngDevMode && assertIndexInRange(lView, index);
812 const def = tView.data[index] as DirectiveDef<unknown>;
813 const hostDirectivePublicName = hostDirectiveInputs[i + 1] as string;
814 writeToDirectiveInput(def, lView[index], hostDirectivePublicName, value);
815 hasSet = true;
816 } else if (index > hostDirectivesEnd) {
817 // Directives here are in ascending order so we can stop looking once we're past the range.
818 break;
819 }
820 }
821 }
822
823 if (hostIndex !== null && Object.hasOwn(target.inputs, publicName)) {
824 ngDevMode && assertIndexInRange(lView, hostIndex);
825 writeToDirectiveInput(target, lView[hostIndex], publicName, value);
826 hasSet = true;
827 }
828
829 return hasSet;
830}

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