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

Method setInput

packages/core/src/render3/component_ref.ts:621–652  ·  view source on GitHub ↗
(name: string, value: unknown)

Source from the content-addressed store, hash-verified

619 }
620
621 override setInput(name: string, value: unknown): void {
622 if (this._hasInputBindings && ngDevMode) {
623 throw new RuntimeError(
624 RuntimeErrorCode.INVALID_SET_INPUT_CALL,
625 'Cannot call `setInput` on a component that is using the `inputBinding` or `twoWayBinding` functions.',
626 );
627 }
628
629 const tNode = this._tNode;
630 this.previousInputValues ??= new Map();
631 // Do not set the input if it is the same as the last value
632 // This behavior matches `bindingUpdated` when binding inputs in templates.
633 if (
634 this.previousInputValues.has(name) &&
635 Object.is(this.previousInputValues.get(name), value)
636 ) {
637 return;
638 }
639
640 const lView = this._rootLView;
641 const hasSetInput = setAllInputsForProperty(tNode, lView[TVIEW], lView, name, value);
642 this.previousInputValues.set(name, value);
643 const childComponentLView = getComponentLViewByIndex(tNode.index, lView);
644 markViewDirty(childComponentLView, NotificationSource.SetInput);
645
646 if (ngDevMode && !hasSetInput) {
647 const cmpNameForError = stringifyForError(this.componentType);
648 let message = `Can't set value of the '${name}' input on the '${cmpNameForError}' component. `;
649 message += `Make sure that the '${name}' property is declared as an input using the input() or model() function or the @Input() decorator.`;
650 reportUnknownPropertyError(message);
651 }
652 }
653
654 override get injector(): Injector {
655 return new NodeInjector(this._tNode, this._rootLView);

Calls 8

setAllInputsForPropertyFunction · 0.90
getComponentLViewByIndexFunction · 0.90
markViewDirtyFunction · 0.90
stringifyForErrorFunction · 0.90
hasMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by 4

configureTestingModuleFunction · 0.64
configureTestingModuleFunction · 0.64
getCdLabelFunction · 0.64
setCdDataFunction · 0.64