Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { EmailValidators } from 'ngx-validators';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-reactive-email-validator',
templateUrl: './email-validator.component.html',
styleUrls: ['./email-validator.component.css']
})
export class ReactiveFormEmailValidatorComponent implements OnInit {
form: FormGroup;
email = new FormControl('', Validators.compose([EmailValidators.normal]));
constructor(protected _fb: FormBuilder) { }
ngOnInit() {
this.form = this._fb.group({
'email': this.email,
});
}
}
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { EmailValidators } from 'ngx-validators';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-reactive-email',
templateUrl: './reactive-form-email.component.html'
})
export class ReactiveFormEmailComponent implements OnInit {
form: FormGroup;
email = new FormControl('', Validators.compose([EmailValidators.normal]));
constructor(protected _fb: FormBuilder) { }
ngOnInit() {
this.form = this._fb.group({
'email': this.email,
});
}
addToForm(email) {
this.form.get('email').setValue(email);
}
}