import {Component} from '@angular/core'; import {FormGroup, AbstractControl, FormBuilder, Validators} from '@angular/forms'; import 'style-loader!./login.scss'; @Component({ selector: 'login', templateUrl: './login.html', }) export class Login { public form:FormGroup; public email:AbstractControl; public password:AbstractControl; public submitted:boolean = false; constructor(fb:FormBuilder) { this.form = fb.group({ 'email': ['', Validators.compose([Validators.required, Validators.minLength(4)])], 'password': ['', Validators.compose([Validators.required, Validators.minLength(4)])] }); this.email = this.form.controls['email']; this.password = this.form.controls['password']; } public onSubmit(values:Object):void { this.submitted = true; if (this.form.valid) { // your code goes here // console.log(values); } } }