import { Component , OnInit } from '@angular/core' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; @ Component ( { selector : 'app-form-demo' , templateUrl : './form-demo.component.html' , styleUrls : [ './form-demo.component.css' ] } ) export class FormDemoComponent implements OnInit { user : FormGroup ; constructor ( private fb ) { } ngOnInit ( ) { this . user = this . fb . group ( { name : [ '' , [ Validators . required , Validators . minLength ( 2 ) ] ] , account : this . fb . group ( { email : [ '' , Validators . required ] , confirm : [ '' , Validators . required ] } ) } ) ; } }