Skip to content

Instantly share code, notes, and snippets.

@jhades
Last active June 30, 2022 07:12
Show Gist options
  • Save jhades/2d678f0140a013ec3d0b5eb2e450944c to your computer and use it in GitHub Desktop.
Save jhades/2d678f0140a013ec3d0b5eb2e450944c to your computer and use it in GitHub Desktop.
@Component({
selector: 'login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
form = this.fb.group({
email: ["", {
validators: [Validators.required, Validators.email]
}],
password: ['', [Validators.required, Validators.minLength(8)]]
});
constructor(private fb: FormBuilder) {
}
login() {
}
}
@Component({
selector: 'login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
form:FormGroup;
constructor(private fb: FormBuilder) {
}
ngOnInit() {
this.form = this.fb.group({
email: ["", {
validators: [Validators.required, Validators.email]
}],
password: ['', [Validators.required, Validators.minLength(8)]]
});
}
}
form: FormGroup<{
email: FormControl<string | null>,
password:FormControl<string | null>
}>;
form = new FormGroup({
email: new FormControl<string | null>("", {
validators: [Validators.required, Validators.email]
}),
password: new FormControl<string | null>("",
{
validators: [Validators.required, Validators.minLength(8)]
}),
});
form = new FormGroup({
email: new FormControl<string | null>("", {
validators: [Validators.required, Validators.email],
nonNullable: true
}),
password: new FormControl<string | null>("",
{
validators: [Validators.required, Validators.minLength(8)]
}),
});
form = this.fb.group({
email: this.fb.nonNullable.control("", {
validators: [Validators.required, Validators.email],
}),
password: ['', [Validators.required, Validators.minLength(8)]]
});
reset() {
this.form.reset();
console.log(this.form.value);
}
@Component({
selector: 'login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
form = this.fb.group({
email: ["", {
validators: [Validators.required, Validators.email]
}],
password: ["", [Validators.required, Validators.minLength(8)] ]
});;
constructor(private fb: NonNullableFormBuilder) {
}
}
form = new FormGroup({
email: new FormControl<string | null>("", {
validators: [Validators.required, Validators.email]
}),
password: new FormControl<string | null>("", {
validators: [Validators.required, Validators.minLength(8)]
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment