null. What does this mean for the form control's validity?function myValidator(control: AbstractControl): ValidationErrors | null { return null; }
In Angular, a validator returns null to indicate the control is valid. Any object returned means errors.
A custom validator must return null if valid or an object with error info if invalid. Option C follows this pattern correctly.
errors property after validation?function startsWithAValidator(control: AbstractControl): ValidationErrors | null { return control.value.startsWith('A') ? null : { startsWithA: true }; } const control = new FormControl('abc', startsWithAValidator); const errors = control.errors;
The value 'abc' does not start with 'A', so the validator returns the error object { startsWithA: true }. This sets the control's errors property.
function positiveNumberValidator(control: AbstractControl): ValidationErrors | null { if (control.value == null || control.value <= 0) { return { notPositive: true }; } return null; }
If control.value is null or undefined, the comparison control.value <= 0 throws a runtime error because you cannot compare null/undefined with a number.
Option A correctly returns a function that takes a control and returns errors or null. This pattern allows passing parameters to the validator.
