DEV Community

Discussion on: Template Forms are just as powerful as Reactive Forms

Collapse
 
anduser96 profile image
Andrei Gatej • Edited

Thanks for the article!

Do you want to validate the email? [input][type="email"].

I think you'd want to use one of the below selectors in order to bind the email validator to your FormControl.

@Directive({
  selector: '[email][formControlName],[email][formControl],[email][ngModel]',
  providers: [EMAIL_VALIDATOR]
})
export class EmailValidator implements Validator {}

Also

You would need to track the submitted status yourself. A Reactive Drive Form is just a Form Group, so it won't have any additional properties.

I don't think this is true. FormGroupDirective

Collapse
 
michaeljota profile image
Michael De Abreu

I think you'd want to use one of the below selectors in order to bind the email validator to your FormControl.

Template forms have several directive validators by default that target standard HTML properties, like email.

I don't think this is true. FormGroupDirective

I didn't know about that. I guess you could use that, but you would need a template reference to that form directive. I wouldn't like to mix up and have some things in the template and other in the code. As far I know, the form group that you have in your controller doesn't have any additional properties, that's just the directive in the template.