{"record":{"id":"6de50d617df70267","repo":"angular/components","slug":"cannot-pass-multiple-values-into-selectionmodel-wi","errorCode":null,"errorMessage":"Cannot pass multiple values into SelectionModel with single-value mode.","messagePattern":"Cannot pass multiple values into SelectionModel with single-value mode\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cdk/collections/selection-model.ts","lineNumber":252,"sourceCode":"        this._deselectedToEmit.push(value);\n      }\n    }\n  }\n\n  /** Clears out the selected values. */\n  private _unmarkAll() {\n    if (!this.isEmpty()) {\n      this._selection.forEach(value => this._unmarkSelected(value));\n    }\n  }\n\n  /**\n   * Verifies the value assignment and throws an error if the specified value array is\n   * including multiple values while the selection model is not supporting multiple values.\n   */\n  private _verifyValueAssignment(values: T[]) {\n    if (values.length > 1 && !this._multiple && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw getMultipleValuesInSingleSelectionError();\n    }\n  }\n\n  /** Whether there are queued up change to be emitted. */\n  private _hasQueuedChanges() {\n    return !!(this._deselectedToEmit.length || this._selectedToEmit.length);\n  }\n\n  /** Returns a value that is comparable to inputValue by applying compareWith function, returns the same inputValue otherwise. */\n  private _getConcreteValue(inputValue: T, selection?: Set<T>): T {\n    if (!this.compareWith) {\n      return inputValue;\n    } else {\n      selection = selection ?? this._selection;\n      for (let selectedValue of selection) {\n        if (this.compareWith!(inputValue, selectedValue)) {\n          return selectedValue;\n        }","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/collections/selection-model.ts#L234-L270","documentation":"SelectionModel._verifyValueAssignment throws getMultipleValuesInSingleSelectionError() when more than one value is passed to select/deselect/setSelection while the model is in single-value mode (multiple: false). The model can only hold one value, so a multi-value assignment is treated as a developer mistake rather than silently truncating.","triggerScenarios":"Calling model.select(a, b), model.setSelection(a, b), or model.deselect(...values) with arrays of length > 1 on a SelectionModel constructed without multiple: true (also via the convenience wrappers that batch).","commonSituations":"Spreading arrays from an <input multiple> or multi-select UI into a single-mode model; model created before multi-select support was needed; shared selection service reused by both single- and multi-select components.","solutions":["Create the model with multiple: true: new SelectionModel<T>(true).","In single mode, call select(value) with exactly one value (or pass a 1-element array).","Loop over values calling select one at a time if last-wins semantics are desired (with emitSelectionChanges as needed)."],"exampleFix":"// before\nconst sel = new SelectionModel<string>(); // single mode\nsel.select(...chosen);\n\n// after\nconst sel = new SelectionModel<string>(true /* multiple */);\nsel.select(...chosen);","handlingStrategy":"validation","validationCode":"function safeSelect<T>(model: SelectionModel<T>, values: T[]): void {\n  if (values.length > 1 && !model.multiple) {\n    throw new Error('Refusing multi-value select on single-mode SelectionModel');\n  }\n  model.select(...values);\n}","typeGuard":"function isMultipleModel<T>(m: SelectionModel<T>): m is SelectionModel<T> & { multiple: true } {\n  return (m as { multiple?: boolean }).multiple === true;\n}","tryCatchPattern":"try {\n  model.select(...values);\n} catch (e) {\n  if ((e as Error).message.includes('single-value mode')) {\n    model.select(values[0]); // keep first value\n  } else throw e;\n}","preventionTips":["Construct with new SelectionModel(true) whenever arrays may be passed.","Keep selection services typed to a single value unless multiple is set.","Check model.multiple before spreading arrays into select/setSelection."],"tags":["angular","cdk","selection-model","dev-mode-assertion"],"backgroundTag":"single-selection-mode-multiple-values","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}