Skip to content

Commit ad2c57a

Browse files
committed
extra lessons on Angular 14 Typed Forms
1 parent 1b093cc commit ad2c57a

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/app/login-reactive/login-reactive.component.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@
4343

4444
</ng-container>
4545

46-
<button mat-raised-button color="primary" [disabled]="!form.valid">
46+
<button mat-raised-button color="primary" [disabled]="!form.valid" (click)="login()">
4747
Login
4848
</button>
4949

50+
<button mat-raised-button (click)="reset()">
51+
Reset
52+
</button>
53+
5054
</form>
5155

5256
<div class="form-val">

src/app/login-reactive/login-reactive.component.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2-
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
2+
import {FormBuilder, FormControl, FormGroup, NonNullableFormBuilder, Validators} from '@angular/forms';
33
import {createPasswordStrengthValidator} from '../validators/password-strength.validator';
44

55

@@ -11,15 +11,14 @@ import {createPasswordStrengthValidator} from '../validators/password-strength.v
1111
export class LoginReactiveComponent implements OnInit {
1212

1313
form = this.fb.group({
14-
email: ['', {
15-
validators: [Validators.required, Validators.email],
16-
updateOn: 'blur'
17-
}],
14+
email: ["", {
15+
validators: [Validators.required, Validators.email],
16+
updateOn: 'blur'}],
1817
password: ['', [Validators.required, Validators.minLength(8),
1918
createPasswordStrengthValidator()]]
2019
});
2120

22-
constructor(private fb: FormBuilder) {
21+
constructor(private fb: NonNullableFormBuilder) {
2322

2423

2524
}
@@ -36,4 +35,26 @@ export class LoginReactiveComponent implements OnInit {
3635
return this.form.controls['password'];
3736
}
3837

38+
login() {
39+
40+
}
41+
42+
reset() {
43+
this.form.reset();
44+
45+
console.log(this.form.value);
46+
47+
}
3948
}
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+

0 commit comments

Comments
 (0)