Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: FormGroup y se adiciono el evento onClick login #23

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions burguer-queen/src/app/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,35 @@
</div>

<div class="col-md-6 col-lg-6" style="margin-top: 80px;">
<form style="background-color: #EA8D6F; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0,0,0,0.3);"
class="p-3">
<form [formGroup]="formLogin"
style="background-color: #EA8D6F; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0,0,0,0.3);" class="p-3">
<img src="../assets/images/bienvenido.png" alt="Welcome Image" class="img-fluid mx-auto d-block">
<div class="form-group mt-3">
<label for="exampleInputEmail1">Email</label>
<input type="email" class="form-control" [formControl]="email" id="exampleInputEmail1" aria-describedby="emailHelp"
placeholder="[email protected]" style="width: 100%; margin-left: 5px;">
<input type="email" class="form-control" formControlName="email" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="[email protected]" style="width: 100%; margin-left: 5px;">

<div class="alert alert-danger mt-3 p-1" [hidden]="email.valid">
<span *ngIf="email.errors?.['email']">
El email debe ser válido.
</span>
</div>
El email debe ser válido.
</div>
</div>
<div class="form-group mt-3">
<label for="exampleInputPassword1">Contraseña</label>
<input type="password" class="form-control" [formControl]="password" id="exampleInputPassword1" placeholder="********"
style="width: 100%; margin-left: 5px;">
<input type="password" class="form-control" formControlName="password" id="exampleInputPassword1"
placeholder="********" style="width: 100%; margin-left: 5px;">

<div class="alert alert-danger mt-3 p-1" [hidden]="password.valid || password.pristine"> El campo debe estar lleno. </div>
<div class="alert alert-danger mt-3 p-1"
[hidden]="password.valid || password.pristine"> El campo debe estar
lleno. </div>
</div>
<button type="submit" class="btn btn-warning mx-auto d-block mt-3"
style="background-color: #FDE293;">INICIAR SESIÓN</button>
<button type="submit" class="btn btn-warning mx-auto d-block mt-3" [disabled]="formLogin.invalid" style="background-color: #FDE293;" (click)="onClickLogin()">INICIAR
SESIÓN</button>
</form>
</div>
{{ email.value }}
{{ email.errors | json }}
<!-- {{ email.value }}
{{ email.errors | json }} -->
<!-- {{ formLogin.value | json }} -->
{{ formLogin.get('email')?.value }} <!--método get accedo a los objetos de manera individual -->

</div>
</div>

20 changes: 17 additions & 3 deletions burguer-queen/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { Component } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent {
onClickLogin(){
console.log("onClickLogin")
}

get email(){
return this.formLogin.get('email') as FormControl;//as formcontrol es para quitar el error y no usar ? en html
}

get password(){
return this.formLogin.get('password') as FormControl;
}
formLogin = new FormGroup({
'email' : new FormControl('', Validators.email),
'password' : new FormControl('',Validators.required)
})

email = new FormControl('', Validators.email);
password = new FormControl('',Validators.required);

}