mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-18 14:22:35 +00:00
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { FuseLayoutService } from '../../../../../core/services/layout.service';
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
@Component({
|
|
selector : 'fuse-login',
|
|
templateUrl: './login.component.html',
|
|
styleUrls : ['./login.component.scss']
|
|
})
|
|
export class FuseLoginComponent implements OnInit
|
|
{
|
|
loginForm: FormGroup;
|
|
loginFormErrors: any;
|
|
|
|
constructor(
|
|
private layoutService: FuseLayoutService,
|
|
private formBuilder: FormBuilder
|
|
)
|
|
{
|
|
this.layoutService.setSettings({
|
|
navigation: 'none',
|
|
toolbar : 'none',
|
|
footer : 'none'
|
|
});
|
|
|
|
this.loginFormErrors = {
|
|
email : {},
|
|
password: {}
|
|
};
|
|
}
|
|
|
|
ngOnInit()
|
|
{
|
|
this.loginForm = this.formBuilder.group({
|
|
email : ['', [Validators.required, Validators.email]],
|
|
password: ['', Validators.required]
|
|
});
|
|
|
|
this.loginForm.valueChanges.subscribe(() => {
|
|
this.onLoginFormValuesChanged();
|
|
});
|
|
}
|
|
|
|
onLoginFormValuesChanged()
|
|
{
|
|
for ( const field in this.loginFormErrors )
|
|
{
|
|
if ( !this.loginFormErrors.hasOwnProperty(field) )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Clear previous errors
|
|
this.loginFormErrors[field] = {};
|
|
|
|
// Get the control
|
|
const control = this.loginForm.get(field);
|
|
|
|
if ( control && control.dirty && !control.valid )
|
|
{
|
|
this.loginFormErrors[field] = control.errors;
|
|
}
|
|
}
|
|
}
|
|
}
|