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

Method setInput

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

Source from the content-addressed store, hash-verified

576 }
577
578 override setInput(name: string, value: unknown): void {
579 if (this._hasInputBindings && ngDevMode) {
580 throw new RuntimeError(
581 RuntimeErrorCode.INVALID_SET_INPUT_CALL,
582 'Cannot call `setInput` on a component that is using the `inputBinding` or `twoWayBinding` functions.',
583 );
584 }
585
586 const tNode = this._tNode;
587 this.previousInputValues ??= new Map();
588 // Do not set the input if it is the same as the last value
589 // This behavior matches `bindingUpdated` when binding inputs in templates.
590 if (
591 this.previousInputValues.has(name) &&
592 Object.is(this.previousInputValues.get(name), value)
593 ) {
594 return;
595 }
596
597 const lView = this._rootLView;
598 const hasSetInput = setAllInputsForProperty(tNode, lView[TVIEW], lView, name, value);
599 this.previousInputValues.set(name, value);
600 const childComponentLView = getComponentLViewByIndex(tNode.index, lView);
601 markViewDirty(childComponentLView, NotificationSource.SetInput);
602
603 if (ngDevMode && !hasSetInput) {
604 const cmpNameForError = stringifyForError(this.componentType);
605 let message = `Can't set value of the '${name}' input on the '${cmpNameForError}' component. `;
606 message += `Make sure that the '${name}' property is declared as an input using the input() or model() function or the @Input() decorator.`;
607 reportUnknownPropertyError(message);
608 }
609 }
610
611 override get injector(): Injector {
612 return new NodeInjector(this._tNode, this._rootLView);

Callers 15

reactivity_spec.tsFile · 0.80
directive_spec.tsFile · 0.80
writeToDirectiveInputFunction · 0.80
_applyInputStateDiffMethod · 0.80
subscribeToRouteDataMethod · 0.80
setInputValueMethod · 0.80
setInputFunction · 0.80

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 3

configureTestingModuleFunction · 0.64
configureTestingModuleFunction · 0.64
getCdLabelFunction · 0.64