{"record":{"id":"c34682bcc1bccc4b","repo":"angular/components","slug":"value-of-options-input-cannot-be-an-empty-array","errorCode":null,"errorMessage":"Value of `options` input cannot be an empty array","messagePattern":"Value of `options` input cannot be an empty array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material/timepicker/timepicker.ts","lineNumber":229,"sourceCode":"  readonly disabled: Signal<boolean> = computed(() => !!this._input()?.disabled());\n\n  /** Classes to be passed to the timepicker panel. */\n  readonly panelClass = input<string | string[]>();\n\n  constructor() {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      validateAdapter(this._dateAdapter, this._dateFormats);\n\n      effect(() => {\n        const options = this.options();\n        const interval = this.interval();\n\n        if (options !== null && interval !== null) {\n          throw new Error(\n            'Cannot specify both the `options` and `interval` inputs at the same time',\n          );\n        } else if (options?.length === 0) {\n          throw new Error('Value of `options` input cannot be an empty array');\n        }\n      });\n    }\n\n    // Since the panel ID is static, we can set it once without having to maintain a host binding.\n    const element = inject<ElementRef<HTMLElement>>(ElementRef);\n    element.nativeElement.setAttribute('mat-timepicker-panel-id', this.panelId);\n    this._handleLocaleChanges();\n    this._handleInputStateChanges();\n    this._keyManager.change.subscribe(() =>\n      this._activeDescendant.set(this._keyManager.activeItem?.id || null),\n    );\n  }\n\n  /** Opens the timepicker. */\n  open(): void {\n    const input = this._input();\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/timepicker/timepicker.ts#L211-L247","documentation":"MatTimepicker validates that the `options` input is not an empty array — an empty list would render a picker with no selectable times. The same constructor effect that guards against options+interval throws when options is non-null but has length 0.","triggerScenarios":"Binding [options]=\"[]\" (or a computed/filter that yields an empty array) on <mat-timepicker>.","commonSituations":"Filtering a time list by business hours where the filter result is empty at init; initializing options to [] before async data arrives; calling setInput('options', []) in tests.","solutions":["Ensure the array passed to [options] has at least one entry","Initialize options only after data loads, or fall back to a default list","If no options are valid yet, set options to null and use `interval` or hide the timepicker"],"exampleFix":"// before\noptions = signal<MatTimepickerOption[]>([]);\n\n// after\noptions = signal<MatTimepickerOption[] | null>(null); // set real options once loaded\n// or guard: only bind when (options()?.length ?? 0) > 0","handlingStrategy":"validation","validationCode":"function validOptions(options: MatTimepickerOption[] | null): boolean {\n  return options === null || options.length > 0;\n}\n// usage\nif (!validOptions(this.options())) throw new Error('options must be null or non-empty');","typeGuard":"function isNonEmptyOptions(o: MatTimepickerOption[] | null): o is MatTimepickerOption[] {\n  return o !== null && o.length > 0;\n}","tryCatchPattern":"try {\n  this.options.set(candidate);\n} catch (e) {\n  if (String(e?.message).includes('empty array')) {\n    this.options.set(null); // fall back to interval/default behavior\n  }\n}","preventionTips":["Never bind a literal [] to [options]","Fall back to null (or interval) when a filtered list is empty","Load async options before enabling the timepicker","Unit-test option filters to catch empty results early"],"tags":["angular-material","timepicker","input-validation","dev-mode"],"backgroundTag":"empty-array-input","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}