Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active October 28, 2021 14:30
Show Gist options
  • Save NyaGarcia/d2bc2bb91bcc1426515664631b2c731f to your computer and use it in GitHub Desktop.
Save NyaGarcia/d2bc2bb91bcc1426515664631b2c731f to your computer and use it in GitHub Desktop.
Creating a login form
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