formgroup and formcontrol in angular 6 example

Example 1: formgroup addcontrol

let form: FormGroup = new FormGroup({});
form.addControl(field_name, new FormControl('', Validators.required));

Example 2: formgroup angular

content_copy
      
      const form = new FormGroup({
  first: new FormControl('Nancy', Validators.minLength(2)),
  last: new FormControl('Drew'),
});

console.log(form.value);   // {first: 'Nancy', last; 'Drew'}
console.log(form.status);  // 'VALID'

Example 3: get formcontrol value

this.loginForm = new FormGroup({
  'email': new FormControl('', { validators: [Validators.required] })
});
// get like this
const { email } = this.loginForm.value;

Tags:

Html Example