MCPcopy Create free account
hub / github.com/angular/components / _selectOptionByValue

Method _selectOptionByValue

src/material/select/select.ts:1070–1098  ·  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

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