Bird
0
0

Find the bug in this custom validator: function forbiddenNameValidator(name: string) { return (control: AbstractControl): ValidationErrors | null => { return control.value === name ?

medium📝 Debug Q7 of 15
Angular - Reactive Forms
Find the bug in this custom validator: function forbiddenNameValidator(name: string) { return (control: AbstractControl): ValidationErrors | null => { return control.value === name ? { forbiddenName: { value: name } } : null; }; }
AIncorrect comparison operator used
BNo bug, this is a valid factory validator
CMissing return type on outer function
DShould not use arrow function inside
Step-by-Step Solution
Solution:
  1. Step 1: Understand validator factory pattern

    This function returns a validator function customized by the 'name' parameter.
  2. Step 2: Check syntax and logic

    The inner function compares control value to name and returns error or null correctly.
  3. Final Answer:

    No bug, this is a valid factory validator -> Option B
  4. Quick Check:

    Validator factory returns a validator function [OK]
Quick Trick: Validator factories return functions that validate [OK]
Common Mistakes:
MISTAKES
  • Expecting outer function to be a validator itself
  • Confusing arrow function usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes