I have the following attribute directive to perform form validation. My @NgModule includes it in it's declarations array. My form is in a component's template. How would I add the appCarrierFormValidation attribute to my form to be able to use this directive and validate the inputs?
import { Directive } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
@Directive({
selector: '[appCarrierFormValidation]'
})
export class CarrierFormValidationDirective {
addCarrierForm: FormGroup;
constructor(private fb: FormBuilder) {
this.createForm();
}
createForm() {
this.addCarrierForm = this.fb.group({
name: ['', Validators.required],
email: ['', [Validators.required, Validators.email]]
})
}
}
appCarrierFormValidation?appCarrierFormValidationis just the attribute selector to use in the template right?AddCarriersComponentwhose template contains a form,form [formGroup]="addCarrierForm"This form contains those 2 controls that require validation.