{"record":{"id":"b29eaca7db0c1de3","repo":"angular/components","slug":"mattimepicker-can-only-be-registered-with-one-inpu","errorCode":null,"errorMessage":"MatTimepicker can only be registered with one input at a time","messagePattern":"MatTimepicker can only be registered with one input at a time","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material/timepicker/timepicker.ts","lineNumber":303,"sourceCode":"\n  /** Closes the timepicker. */\n  close(): void {\n    if (this._isOpen()) {\n      this._isOpen.set(false);\n      this.closed.emit();\n\n      if (this._animationsDisabled) {\n        this._overlayRef?.detach();\n      }\n    }\n  }\n\n  /** Registers an input with the timepicker. */\n  registerInput(input: MatTimepickerConnectedInput<D>): void {\n    const currentInput = this._input();\n\n    if (currentInput && input !== currentInput && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw new Error('MatTimepicker can only be registered with one input at a time');\n    }\n\n    this._input.set(input);\n  }\n\n  ngOnDestroy(): void {\n    this._keyManager.destroy();\n    this._localeChanges?.unsubscribe();\n    this._onOpenRender?.destroy();\n    this._overlayRef?.dispose();\n  }\n\n  _getOverlayHost() {\n    return this._overlayRef?.hostElement;\n  }\n\n  /** Selects a specific time value. */\n  protected _selectValue(option: MatOption<D>) {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/timepicker/timepicker.ts#L285-L321","documentation":"A single MatTimepicker instance can be connected to exactly one input (MatTimepickerInput or a custom MatTimepickerConnectedInput). registerInput throws if a second, different input tries to register while one is already attached, preventing two inputs from driving the same picker's state.","triggerScenarios":"Reusing one <mat-timepicker> template instance for two <input [matTimepicker]> fields; a destroyed-and-recreated input racing registration; programmatically calling registerInput for a new input without deregistering the old one.","commonSituations":"Sharing a picker across multiple form fields in a template (ng-template reuse), conditional rendering that creates a second input before the first unregisters, or custom connected-input implementations.","solutions":["Give each <input [matTimepicker]> its own <mat-timepicker> instance","If sharing is intentional, wait for the first input to be destroyed/deregistered before registering the new one","Check for duplicated template ref usage (e.g. the same #picker passed to multiple inputs)"],"exampleFix":"// before\n<input [matTimepicker]=\"picker\" />\n<input [matTimepicker]=\"picker\" />\n<mat-timepicker #picker></mat-timepicker>\n\n// after\n<input [matTimepicker]=\"picker1\" />\n<mat-timepicker #picker1></mat-timepicker>\n<input [matTimepicker]=\"picker2\" />\n<mat-timepicker #picker2></mat-timepicker>","handlingStrategy":"validation","validationCode":"// Check registration exclusivity before wiring inputs\nfunction assertSingleInput(pickers: HTMLElement[]): void {\n  const ids = new Set(pickers.map(p => p.id));\n  if (ids.size < pickers.length) {\n    throw new Error('Multiple inputs share the same mat-timepicker');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  input.registerWithPicker(picker);\n} catch (e) {\n  if (String(e?.message).includes('one input at a time')) {\n    console.error('Create a dedicated <mat-timepicker> per input.');\n  }\n}","preventionTips":["One <mat-timepicker> per <input [matTimepicker]>","Avoid reusing the same template ref (#picker) across inputs","When swapping inputs programmatically, let the old input destroy/deregister first","Search templates for duplicated picker references in code review"],"tags":["angular-material","timepicker","registration","dev-mode"],"backgroundTag":"component-already-registered","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}