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

Method _getIndexForValue

src/cdk/listbox/listbox.ts:943–956  ·  view source on GitHub ↗

* Gets the index of the given value in the given list of options. * @param cache The cache of indices found so far * @param value The value to find * @return The index of the value in the options list

(cache: Map<T, number>, value: T)

Source from the content-addressed store, hash-verified

941 * @return The index of the value in the options list
942 */
943 private _getIndexForValue(cache: Map<T, number>, value: T) {
944 const isEqual = this.compareWith || Object.is;
945 if (!cache.has(value)) {
946 let index = -1;
947 for (let i = 0; i < this.options.length; i++) {
948 if (isEqual(value, this.options.get(i)!.value)) {
949 index = i;
950 break;
951 }
952 }
953 cache.set(value, index);
954 }
955 return cache.get(value)!;
956 }
957
958 /**
959 * Handle the user clicking an option.

Callers 1

_updateInternalValueMethod · 0.95

Calls 2

setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected