MCPcopy Index your code
hub / github.com/angular/components / _selectOptionByValue

Method _selectOptionByValue

src/material/select/select.ts:1068–1096  ·  view source on GitHub ↗

* Finds and selects and option based on its value. * @returns Option that has the corresponding value.

(value: any)

Source from the content-addressed store, hash-verified

1066 * @returns Option that has the corresponding value.
1067 */
1068 private _selectOptionByValue(value: any): MatOption | undefined {
1069 const correspondingOption = this.options.find((option: MatOption) => {
1070 // Skip options that are already in the model. This allows us to handle cases
1071 // where the same primitive value is selected multiple times.
1072 if (this._selectionModel.isSelected(option)) {
1073 return false;
1074 }
1075
1076 try {
1077 // Treat null as a special reset value.
1078 return (
1079 (option.value != null || this.canSelectNullableOptions) &&
1080 this._compareWith(option.value, value)
1081 );
1082 } catch (error) {
1083 if (typeof ngDevMode === 'undefined' || ngDevMode) {
1084 // Notify developers of errors in their comparator.
1085 console.warn(error);
1086 }
1087 return false;
1088 }
1089 });
1090
1091 if (correspondingOption) {
1092 this._selectionModel.select(correspondingOption);
1093 }
1094
1095 return correspondingOption;
1096 }
1097
1098 /** Assigns a specific value to the select. Returns whether the value has changed. */
1099 private _assignValue(newValue: any | any[]): boolean {

Callers 1

_setSelectionByValueMethod · 0.95

Calls 3

warnMethod · 0.80
isSelectedMethod · 0.65
selectMethod · 0.65

Tested by

no test coverage detected