Angular - Reactive FormsWhy should a custom validator function in Angular always return null when the input is valid instead of undefined or other values?ABecause Angular ignores null and treats undefined as validBBecause undefined causes the form to resetCBecause Angular treats null as no error and any other value as an errorDBecause returning undefined disables the controlCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand Angular validation contractAngular expects validators to return null if valid, or an error object if invalid.Step 2: Effect of return valuesReturning null signals no error; any other value (including undefined) is treated as an error.Final Answer:Because Angular treats null as no error and any other value as an error -> Option CQuick Check:Return null for valid input to avoid errors [OK]Quick Trick: Return null for valid input, anything else signals error [OK]Common Mistakes:MISTAKESReturning undefined and expecting validReturning empty object instead of null
Master "Reactive Forms" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Change Detection - Zone.js and automatic detection - Quiz 1easy Angular Change Detection - Default change detection strategy - Quiz 12easy Angular Change Detection - Performance impact of change detection - Quiz 4medium HTTP Client - GET requests - Quiz 5medium Reactive Forms - Validators (required, minLength, pattern) - Quiz 13medium Reactive Forms - FormControl basics - Quiz 2easy RxJS Operators - tap operator for side effects - Quiz 4medium RxJS and Observables Fundamentals - Observable in component lifecycle - Quiz 3easy Services and Dependency Injection - How dependency injection works in Angular - Quiz 13medium Services and Dependency Injection - Why services are needed - Quiz 8hard