( dir: NgControl, valueAccessors: readonly ControlValueAccessor[] | null | undefined, )
| 399 | |
| 400 | // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented |
| 401 | export function selectValueAccessor( |
| 402 | dir: NgControl, |
| 403 | valueAccessors: readonly ControlValueAccessor[] | null | undefined, |
| 404 | ): ControlValueAccessor | null { |
| 405 | if (!valueAccessors) return null; |
| 406 | |
| 407 | if (!Array.isArray(valueAccessors) && (typeof ngDevMode === 'undefined' || ngDevMode)) |
| 408 | _throwInvalidValueAccessorError(dir); |
| 409 | |
| 410 | let defaultAccessor: ControlValueAccessor | undefined = undefined; |
| 411 | let builtinAccessor: ControlValueAccessor | undefined = undefined; |
| 412 | let customAccessor: ControlValueAccessor | undefined = undefined; |
| 413 | |
| 414 | valueAccessors.forEach((v: ControlValueAccessor) => { |
| 415 | if (v.constructor === DefaultValueAccessor) { |
| 416 | defaultAccessor = v; |
| 417 | } else if (isBuiltInAccessor(v)) { |
| 418 | if (builtinAccessor && (typeof ngDevMode === 'undefined' || ngDevMode)) |
| 419 | _throwError(dir, 'More than one built-in value accessor matches form control with'); |
| 420 | builtinAccessor = v; |
| 421 | } else { |
| 422 | if (customAccessor && (typeof ngDevMode === 'undefined' || ngDevMode)) |
| 423 | _throwError(dir, 'More than one custom value accessor matches form control with'); |
| 424 | customAccessor = v; |
| 425 | } |
| 426 | }); |
| 427 | |
| 428 | if (customAccessor) return customAccessor; |
| 429 | if (builtinAccessor) return builtinAccessor; |
| 430 | if (defaultAccessor) return defaultAccessor; |
| 431 | |
| 432 | if (typeof ngDevMode === 'undefined' || ngDevMode) { |
| 433 | _throwError(dir, 'No valid value accessor for form control with'); |
| 434 | } |
| 435 | return null; |
| 436 | } |
| 437 | |
| 438 | export function removeListItem<T>(list: T[], el: T): void { |
| 439 | const index = list.indexOf(el); |
no test coverage detected