Last active
October 28, 2021 14:30
-
-
Save NyaGarcia/d2bc2bb91bcc1426515664631b2c731f to your computer and use it in GitHub Desktop.
Creating a login form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; | |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | |
@Component({ | |
selector: 'ngbytes-login-form', | |
templateUrl: './login-form.component.html', | |
styleUrls: ['./login-form.component.css'], | |
}) | |
export class LoginFormComponent implements OnInit { | |
@Output() formData: EventEmitter<{ | |
email: string; | |
password: string; | |
}> = new EventEmitter(); | |
form: FormGroup; | |
constructor(private fb: FormBuilder) {} | |
ngOnInit(): void { | |
this.form = this.fb.group({ | |
email: ['', [Validators.required, Validators.email]], | |
password: ['', Validators.required], | |
}); | |
} | |
get email() { | |
return this.form.get('email'); | |
} | |
get password() { | |
return this.form.get('password'); | |
} | |
onSubmit() { | |
this.formData.emit(this.form.value); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment