I have a field I want to validate with multiple validators.
Using the Module Driven approach the code looks likes this:
this.exampleForm = this.fb.group({
date_start : [
'',
Validators.compose([
Validators.required,
Validators.pattern("[0-9]{2}-[0-9]{2}-[0-9]{4}")
])]
})
But I can also write this withouth Validators.compose() like:
this.exampleForm = this.fb.group({
date_start : [
'',
[
Validators.required,
Validators.pattern("[0-9]{2}-[0-9]{2}-[0-9]{4}")
]
]
})
And it works just fine. Personally I prefer the 2nd version (without compose), less code and better readability. And this begs the question, why should I use Validators.compose()?
compose()
was removed, but I guess they kept it to not unnecessarily break existing code and confuse users. – HeterodyneValidatorFn
instead ofarray
. It won't be necessary only when they merge this pull request. – Dennett