{"record":{"id":"98d3489b791a401c","repo":"angular/components","slug":"value-must-be-an-array-in-multiple-selection-mode-98d348","errorCode":null,"errorMessage":"Value must be an array in multiple-selection mode.","messagePattern":"Value must be an array in multiple-selection mode\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/select/select.ts","lineNumber":1044,"sourceCode":"        this._value = this.ngControl.value;\n      }\n\n      this._setSelectionByValue(this._value);\n      this.stateChanges.next();\n    });\n  }\n\n  /**\n   * Sets the selected option based on a value. If no option can be\n   * found with the designated value, the select trigger is cleared.\n   */\n  private _setSelectionByValue(value: any | any[]): void {\n    this.options.forEach(option => option.setInactiveStyles());\n    this._selectionModel.clear();\n\n    if (this.multiple && value) {\n      if (!Array.isArray(value) && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n        throw getMatSelectNonArrayValueError();\n      }\n\n      value.forEach((currentValue: any) => this._selectOptionByValue(currentValue));\n      this._sortValues();\n    } else {\n      const correspondingOption = this._selectOptionByValue(value);\n\n      // Shift focus to the active item. Note that we shouldn't do this in multiple\n      // mode, because we don't know what option the user interacted with last.\n      if (correspondingOption) {\n        this._keyManager.updateActiveItem(correspondingOption);\n      } else if (!this.panelOpen) {\n        // Otherwise reset the highlighted option. Note that we only want to do this while\n        // closed, because doing it while open can shift the user's focus unnecessarily.\n        this._keyManager.updateActiveItem(-1);\n      }\n    }\n","sourceCodeStart":1026,"sourceCodeEnd":1062,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/select/select.ts#L1026-L1062","documentation":"MatSelect throws this in dev mode when the form-control value bound to a multi-select (`multiple=\"true\"`) is not an array. `_setSelectionByValue` iterates `value.forEach(...)` for multi-selection, so a non-array value cannot be applied. It is a developer-facing contract error: multi-select values must always be `any[]`.","triggerScenarios":"Calling `select.value = 'foo'` (or patching a FormControl with a string) on a `<mat-select multiple>`, or `compareWith`/writeValue invoked with a single object while multiple mode is on.","commonSituations":"Toggling the `multiple` attribute at runtime without converting the existing value from scalar to array; initializing a FormControl with a single item; forgetting `[value]` should be bound as an array in reactive forms.","solutions":["Wrap the bound value in an array (e.g. `this.control.setValue(['foo'])`).","Ensure the `multiple` input is bound statically and not switched after the value is set.","Guard assignments: only pass array values to a multi-select (see validationCode).","If the value comes from a server response, normalize it to an array before assigning."],"exampleFix":"// before\nthis.cityCtrl = new FormControl('nyc'); // mat-select is multiple\n// after\nthis.cityCtrl = new FormControl(['nyc']);","handlingStrategy":"validation","validationCode":"function assertArrayValue(multiple: boolean, value: unknown) {\n  if (multiple && !Array.isArray(value)) {\n    throw new Error('mat-select multiple requires an array value');\n  }\n}\n// call before assigning: assertArrayValue(true, this.control.value);","typeGuard":"function isArrayValue(v: unknown): v is any[] { return Array.isArray(v); }","tryCatchPattern":"try {\n  this.select.value = rawValue as any[];\n} catch (e) {\n  console.error('mat-select multi value must be an array', e);\n  this.select.value = [];\n}","preventionTips":["Initialize FormControl for multi-selects with an array, even if empty ([]).","Never toggle `multiple` after a value is set without converting the value.","Normalize API payloads to arrays before writing them into a multi-select.","Run in dev mode in tests so ngDevMode throws surface early."],"tags":["angular","material","forms","dev-mode"],"backgroundTag":"invalid-form-control-value","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}