Angular 12 References/ Forms
🍀 Angular References

[required] validation directive

A directive that adds the required validator to any controls marked with the required attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

Adding a required validator using template-driven forms

<input name="fullName" ngModel required>


@Input() get required(): boolean|string

Tracks changes to the required attribute bound to this directive.


set required(value: boolean|string)


validate(control: AbstractControl): ValidationErrors|null

Method that validates whether the control is empty. Returns the validation result if enabled, otherwise null.


registerOnValidatorChange(fn: () => void): void

Registers a callback function to call when the validator inputs change.