Skip to main content
Version: 0.9.0

contains

Validate that the array contains every one of the given values (membership via Array.includes). A non-array value fails.

Signature

NguardValidators.Array.contains(...values: primitive[]): ValidatorFn
ParameterTypeDescription
...valuesprimitive[]The values that must all be present

Reactive forms

import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';

new FormControl(['read', 'write'], [NguardValidators.Array.contains('read', 'write')]);

Template-driven forms

<!-- Array form -->
<input ngModel name="scopes" [nguardArrayContains]="['read', 'write']" />

<!-- Single value shorthand -->
<input ngModel name="scopes" [nguardArrayContains]="'read'" />

The directive selector is nguardArrayContains (prefixed to avoid clashing with the String.contains directive).

Error key

{ contains: true }

Notes

  • Membership uses Array.prototype.includes (strict, SameValueZero).
  • A non-array value (including null/undefined) fails.

See also