{"record":{"id":"2ea3567e3e6fd004","repo":"angular/components","slug":"found-multiple-cdkoption-with-the-same-value","errorCode":null,"errorMessage":"Found multiple CdkOption with the same value","messagePattern":"Found multiple CdkOption with the same value","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cdk/listbox/listbox.ts","lineNumber":1003,"sourceCode":"          const other = this.options.get(j)!;\n          if (isEqual(option.value, other.value)) {\n            duplicate = other;\n            break;\n          }\n        }\n        if (duplicate) {\n          // TODO(mmalerba): Link to docs about this.\n          if (this.compareWith) {\n            console.warn(\n              `Found multiple CdkOption representing the same value under the given compareWith function`,\n              {\n                option1: option.element,\n                option2: duplicate.element,\n                compareWith: this.compareWith,\n              },\n            );\n          } else {\n            console.warn(`Found multiple CdkOption with the same value`, {\n              option1: option.element,\n              option2: duplicate.element,\n            });\n          }\n          return;\n        }\n      }\n    });\n  }\n\n  /** Verifies that the option values are valid. */\n  private _verifyOptionValues() {\n    if (this.options && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      const selected = this.selectionModel.selected;\n      const invalidValues = this._getInvalidOptionValues(selected);\n\n      if (!this.multiple && selected.length > 1) {\n        throw Error('Listbox cannot have more than one selected value in single selection mode.');","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/listbox/listbox.ts#L985-L1021","documentation":"This is the default-branch variant of the duplicate-option warning: when no compareWith is supplied, CdkListbox compares option values directly (e.g. by ===/string equality) and warns if two CdkOptions have the same value, since selection by value would be ambiguous.","triggerScenarios":"Two CdkOption components inside a CdkListbox (no compareWith set) have identical values during listbox validation, hitting the else-branch console.warn with both option elements.","commonSituations":"Static templates repeating the same option value; data with duplicate keys rendered into options; typos causing two labels to share one value.","solutions":["Give each cdkOption a unique [value]","De-duplicate the data source before rendering options","If values are legitimately equal-shaped objects, provide a proper [compareWith] and ensure it distinguishes them"],"exampleFix":"// before\n<option [value]=\"'us'\">US</option>\n<option [value]=\"'us'\">USA</option>\n// after\n<option [value]=\"'us'\">US</option>\n<option [value]=\"'usa'\">USA</option>","handlingStrategy":"validation","validationCode":"const values = options.map(o => o.value);\nconst dupes = values.filter((v, i) => values.indexOf(v) !== i);\nif (dupes.length) console.warn('Duplicate option values:', dupes);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind a unique [value] per cdkOption","De-duplicate data before rendering","Use primitive, comparable values (string/number) when possible","If object values are needed, always supply compareWith"],"tags":["listbox","cdk-listbox","duplicate-values"],"backgroundTag":"duplicate-option-value","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}