requiredArrayKeys
Validate that the value is a non-null object containing every one of the given keys. Maps Laravel's required_array_keys rule to a plain object.
Signature
NguardValidators.Array.requiredArrayKeys(...keys: string[]): ValidatorFn
| Parameter | Type | Description |
|---|---|---|
...keys | string[] | The keys that must all be present |
Reactive forms
import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';
new FormControl({ id: 1, name: 'x' }, [
NguardValidators.Array.requiredArrayKeys('id', 'name'),
]);
Template-driven forms
<!-- Array form -->
<input ngModel name="profile" [nguardRequiredArrayKeys]="['id', 'name']" />
<!-- Single key shorthand -->
<input ngModel name="profile" [nguardRequiredArrayKeys]="'id'" />
Error key
{ requiredArrayKeys: true }
Notes
- Presence is checked with the
inoperator, so inherited keys count. null,undefinedand primitives fail — the value must be an object.
See also
array— value is an array