tezvyn:

Create a custom synchronous validator for an Angular Reactive Form

Source: angular.devintermediate

Tests your grasp of the ValidatorFn contract and reactive form wiring. A strong answer: a function accepting AbstractControl returns null when valid or an error object when invalid, passed as the second FormControl argument. Red flag: returning booleans.

Tests your grasp of the ValidatorFn interface and reactive form wiring. A good answer hits four things in order: first, write a plain function that accepts an AbstractControl and reads its value; second, return null for valid or a ValidationErrors object for invalid; third, pass it as the second argument to the FormControl constructor or via setValidators; fourth, read errors with control.hasError or control.errors.

Read the original → angular.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Create a custom synchronous validator for an Angular Reactive Form · Tezvyn