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

Function setDirectiveInput

packages/core/src/render3/instructions/shared.ts:793–849  ·  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

791 * @param value Value to set.
792 */
793export function setDirectiveInput(
794 tNode: TNode,
795 tView: TView,
796 lView: LView,
797 target: DirectiveDef<unknown>,
798 publicName: string,
799 value: unknown,
800): boolean {
801 let hostIndex: number | null = null;
802 let hostDirectivesStart: number | null = null;
803 let hostDirectivesEnd: number | null = null;
804 let hasSet = false;
805
806 if (ngDevMode && !tNode.directiveToIndex?.has(target.type)) {
807 throw new Error(`Node does not have a directive with type ${target.type.name}`);
808 }
809
810 const data = tNode.directiveToIndex!.get(target.type)!;
811
812 if (typeof data === 'number') {
813 hostIndex = data;
814 } else {
815 [hostIndex, hostDirectivesStart, hostDirectivesEnd] = data;
816 }
817
818 if (
819 hostDirectivesStart !== null &&
820 hostDirectivesEnd !== null &&
821 tNode.hostDirectiveInputs &&
822 Object.hasOwn(tNode.hostDirectiveInputs, publicName)
823 ) {
824 const hostDirectiveInputs = tNode.hostDirectiveInputs[publicName];
825
826 for (let i = 0; i < hostDirectiveInputs.length; i += 2) {
827 const index = hostDirectiveInputs[i] as number;
828
829 if (index >= hostDirectivesStart && index <= hostDirectivesEnd) {
830 ngDevMode && assertIndexInRange(lView, index);
831 const def = tView.data[index] as DirectiveDef<unknown>;
832 const hostDirectivePublicName = hostDirectiveInputs[i + 1] as string;
833 writeToDirectiveInput(def, lView[index], hostDirectivePublicName, value);
834 hasSet = true;
835 } else if (index > hostDirectivesEnd) {
836 // Directives here are in ascending order so we can stop looking once we're past the range.
837 break;
838 }
839 }
840 }
841
842 if (hostIndex !== null && Object.hasOwn(target.inputs, publicName)) {
843 ngDevMode && assertIndexInRange(lView, hostIndex);
844 writeToDirectiveInput(target, lView[hostIndex], publicName, value);
845 hasSet = true;
846 }
847
848 return hasSet;
849}

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