{"record":{"id":"43421f9bf14d6b1d","repo":"angular/components","slug":"a-matdatepicker-can-only-be-associated-with-a-sing","errorCode":null,"errorMessage":"A MatDatepicker can only be associated with a single input.","messagePattern":"A MatDatepicker can only be associated with a single input\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material/datepicker/datepicker-base.ts","lineNumber":612,"sourceCode":"\n  /** Emits selected month in year view */\n  _selectMonth(normalizedMonth: D): void {\n    this.monthSelected.emit(normalizedMonth);\n  }\n\n  /** Emits changed view */\n  _viewChanged(view: MatCalendarView): void {\n    this.viewChanged.emit(view);\n  }\n\n  /**\n   * Register an input with this datepicker.\n   * @param input The datepicker input to register with this datepicker.\n   * @returns Selection model that the input should hook itself up to.\n   */\n  registerInput(input: C): MatDateSelectionModel<S, D> {\n    if (this.datepickerInput && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw Error('A MatDatepicker can only be associated with a single input.');\n    }\n    this._inputStateChanges.unsubscribe();\n    this.datepickerInput = input;\n    this._inputStateChanges = input.stateChanges.subscribe(() => this.stateChanges.next(undefined));\n    return this._model;\n  }\n\n  /**\n   * Registers a portal containing action buttons with the datepicker.\n   * @param portal Portal to be registered.\n   */\n  registerActions(portal: TemplatePortal): void {\n    if (this._actionsPortal && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw Error('A MatDatepicker can only be associated with a single actions row.');\n    }\n    this._actionsPortal = portal;\n    this._componentRef?.instance._assignActions(portal, true);\n  }","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/datepicker/datepicker-base.ts#L594-L630","documentation":"registerInput() guards against one MatDatepicker instance being wired to two inputs. Each datepicker can drive exactly one MatDatepickerInput or MatDateRangePickerInput; if a second input attempts to register while one is already assigned, Material throws this dev-mode error.","triggerScenarios":"Binding the same #picker reference via [matDatepicker] on two different inputs; dynamically reusing a single MatDatepicker instance across multiple inputs rendered at once.","commonSituations":"Copying a table cell with an input+datepicker pair but sharing one picker template reference; *ngFor loops where every row's input points to the same [matDatepicker].","solutions":["Give each input its own <mat-datepicker #pickerN> instance.","Inside *ngFor, declare the datepicker inside the loop template so each iteration gets its own.","If one picker must serve multiple fields, switch to mat-date-range-input or open programmatic calendars per field."],"exampleFix":"// before\n<input matInput [matDatepicker]=\"picker\">\n<input matInput [matDatepicker]=\"picker\">\n<mat-datepicker #picker></mat-datepicker>\n\n// after\n<input matInput [matDatepicker]=\"picker1\">\n<input matInput [matDatepicker]=\"picker2\">\n<mat-datepicker #picker1></mat-datepicker>\n<mat-datepicker #picker2></mat-datepicker>","handlingStrategy":"validation","validationCode":"// Guard before sharing a picker reference\nfunction bindPicker(inputCount: number): void {\n  if (inputCount > 1) throw new Error('Each input needs its own <mat-datepicker> instance');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare <mat-datepicker> inside the same *ngFor iteration as its input.","Search templates for a single #picker reference bound on multiple inputs.","Use unique template reference names (picker1, picker2) or inline the picker per input."],"tags":["angular-material","datepicker","template","one-to-one-binding"],"backgroundTag":"datepicker-shared-instance","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}