From d755961053748d0b54a30052c7ef95f32f49bfb3 Mon Sep 17 00:00:00 2001 From: ralacote Date: Fri, 4 Oct 2024 15:13:11 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9veloppement=20du=20composant=20Login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/login/login.component.html | 6 +-- src/app/components/login/login.component.ts | 46 ++++++++++++++----- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/app/components/login/login.component.html b/src/app/components/login/login.component.html index 62d3b3a..32e8530 100644 --- a/src/app/components/login/login.component.html +++ b/src/app/components/login/login.component.html @@ -5,19 +5,19 @@
Login - +
Password - +
- +
diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 16a24bf..a127888 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Output } from '@angular/core'; +import { Component, EventEmitter, Output, ViewChild } from '@angular/core'; import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; @@ -9,6 +9,7 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; import { MatMenuModule } from '@angular/material/menu'; import { User } from '../../models/user.model'; +import { NgIf } from '@angular/common'; @Component({ selector: 'app-login', @@ -21,30 +22,53 @@ import { User } from '../../models/user.model'; MatDatepickerModule, MatNativeDateModule, FormsModule, - ReactiveFormsModule + ReactiveFormsModule, + NgIf ], templateUrl: './login.component.html', styleUrl: './login.component.css' }) + export class LoginComponent { + @Output() addConnectEvent = new EventEmitter(); + + public isButtonVisible = false; + user: User = { login: '', password: '' } loginForm: FormGroup = new FormGroup({ login: new FormControl(this.user.login, Validators.required), password: new FormControl(this.user.password, Validators.required), }); - Connect() { - // if (this.loginForm.invalid) { - // console.log("ERREUR"); - // return; - // } - console.log(this.user.login) - console.log(this.user.password) + connect() { + console.log(this.loginForm.value.login) + console.log(this.loginForm.value.password) + + if (this.loginForm.invalid) { + console.log("ERREUR INVALIDE"); + return; + } - if(this.user.login != this.user.password){ - console.log("ERREUR"); + if(this.loginForm.value.login != this.loginForm.value.password){ + console.log("ERREUR DIFFERENT"); return; } + + this.user = this.loginForm.value; + + this.addConnectEvent.emit(this.user); + this.loginForm.reset(); + this.isButtonVisible = false; + + } + + onInputChange(event: Event) { + if(this.loginForm.value.login != "" && this.loginForm.value.password != ""){ + this.isButtonVisible = true; + } else{ + this.isButtonVisible = false; + } } + }