Skip to content

Commit

Permalink
extra lessons on Angular 14 Typed Forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jhades committed Jun 29, 2022
1 parent 1b093cc commit ad2c57a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/app/login-reactive/login-reactive.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@

</ng-container>

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

<button mat-raised-button (click)="reset()">
Reset
</button>

</form>

<div class="form-val">
Expand Down
33 changes: 27 additions & 6 deletions src/app/login-reactive/login-reactive.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {FormBuilder, FormControl, FormGroup, NonNullableFormBuilder, Validators} from '@angular/forms';
import {createPasswordStrengthValidator} from '../validators/password-strength.validator';


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

form = this.fb.group({
email: ['', {
validators: [Validators.required, Validators.email],
updateOn: 'blur'
}],
email: ["", {
validators: [Validators.required, Validators.email],
updateOn: 'blur'}],
password: ['', [Validators.required, Validators.minLength(8),
createPasswordStrengthValidator()]]
});

constructor(private fb: FormBuilder) {
constructor(private fb: NonNullableFormBuilder) {


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

login() {

}

reset() {
this.form.reset();

console.log(this.form.value);

}
}












0 comments on commit ad2c57a

Please sign in to comment.