File

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

Metadata

Index

Methods

Constructor

constructor(AuthService: AuthService)
Parameters :
Name Type Optional
AuthService AuthService No

Methods

handleFormSubmit
handleFormSubmit(form: NgForm)
Parameters :
Name Type Optional
form NgForm No
Returns : void
import { Component } from '@angular/core';
import { NgForm } from '@angular/forms';
import { AuthService } from '../auth/auth.service'

@Component({
  selector: 'app-login-form',
  templateUrl: './login-form.component.html',
  styleUrls: ['./login-form.component.css']
})
export class LoginFormComponent {

  constructor(private AuthService: AuthService) { }

  handleFormSubmit(form: NgForm): void {
    this.AuthService.login(form.value.name, form.value.email);
  }

}
<div class="container">
    <h2 class="login-title">Log in</h2>

    <form class="login-form" #templateDrivenForm="ngForm" (ngSubmit)="handleFormSubmit(templateDrivenForm)">
        <div>
            <label for="name">Name </label>
            <input id="name" type="text" placeholder="Adel" ngModel name="name" required />
            <span class="text-danger"
                *ngIf="templateDrivenForm.controls['name']?.invalid && templateDrivenForm.controls['name'].dirty">
                Name is required
            </span>
        </div>

        <div>
            <label for="email">Email </label>
            <input id="email" type="email" placeholder="Adel@mail.com" ngModel name="email" required />
            <span class="text-danger"
                *ngIf="templateDrivenForm.controls['email']?.invalid && templateDrivenForm.controls['email'].dirty">
                Email is required
            </span>
        </div>

        <button class="btn btn--form" type="submit" value="Log in" [disabled]="templateDrivenForm.invalid">
            Log in
        </button>
    </form>
</div>

./login-form.component.css

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

html {
    background: linear-gradient(to right bottom, #fbdb89, #f48982);
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 100%;
    background-attachment: fixed;
}

body {
    font-family: sans-serif;
    line-height: 1.4;
    display: flex;
}

.container {
    width: 400px;
    margin: 50px auto;
    padding: 36px 48px 48px 48px;
    background-color: #f2efee;

    border-radius: 11px;
    box-shadow: 0 2.4rem 4.8rem rgba(0, 0, 0, 0.15);
}

.login-title {
    padding: 15px;
    font-size: 22px;
    font-weight: 600;
    text-align: center;
}

.login-form {
    display: grid;
    grid-template-columns: 1fr;
    row-gap: 16px;
}

.login-form label {
    display: block;
    margin-bottom: 8px;
}

.login-form input {
    width: 100%;
    padding: 1.2rem;
    border-radius: 9px;
    border: none;
}

.login-form input:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(253, 242, 233, 0.5);
}

.btn--form {
    background-color: #f48982;
    color: #fdf2e9;
    align-self: end;
    padding: 8px;
}

.btn,
.btn:link,
.btn:visited {
    display: inline-block;
    text-decoration: none;
    font-size: 20px;
    font-weight: 600;
    border-radius: 9px;
    border: none;

    cursor: pointer;
    font-family: inherit;

    transition: all 0.3s;
}

button {
    outline: 1px solid #f48982;
}

.btn--form:hover {
    background-color: #fdf2e9;
    color: #f48982;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""