import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';
@Component({ imports: [WrInput] })
export class MyComponent {}oneOf
Accept only values from a list.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Live demo
Try xs, sm, md, lg or xl. Anything else fails.
Usage
import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';
const size = new FormControl('', [
WrValidators.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
]);API
| Name | Description | Type | Default |
|---|---|---|---|
signature | Call it with the allowed values. | <T>(allowed: readonly T[]) => ValidatorFn | — |
comparison | Strict ===. | — | — |
error key | On failure: { oneOf: { allowed: [...] } }. Empty value passes. | { oneOf: { allowed } } | — |