Reactive Forms
Great Source: Angular Reactive Forms: Tips and Tricks by Netanel Basal
limit validation
export class AppComponent {
control = new FormControl(null, {
validators: Validators.minLength(4),
updateOn: 'blur'
});
}
run validator explicitly / optimize by debouncing
ngOnInit() {
const name = this.group.get('name');
name.valueChanges.pipe(
debounceTime(300),
untilDestroyed(this)
).subscribe(() => name.setErrors(Validators.minLength(2)(name)))
}
disable by default
new FormGroup({
name: new FormControl({ disabled: true, value: null }),
email: new FormControl()
})
// enable / disable explicitly w/o emitting valueChanged event
name.enable({ emitEvent: false });
name.disable({ emitEvent: false });