File

src/app/sign-in-form/sign-in-form.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

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

Methods

handleSubmit
handleSubmit()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

signForm
Type : FormGroup
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { AuthService } from '../auth/auth.service'

@Component({
  selector: 'app-sign-in-form',
  templateUrl: './sign-in-form.component.html',
  styleUrls: ['./sign-in-form.component.css']
})
export class SignInFormComponent implements OnInit {
  signForm!: FormGroup;

  constructor(private AuthService: AuthService) { }
  ngOnInit(): void {
    this.signForm = new FormGroup({
      'name': new FormControl('', [Validators.required]),
      'email': new FormControl('', [Validators.required, Validators.email]),
      'quote': new FormControl('', [Validators.required])
    });
  }

  handleSubmit() {
    this.AuthService.newUser({
      id: 0,
      name: this.signForm.value.name,
      email: this.signForm.value.email,
      quote: this.signForm.value.quote,
    });
 }
  
}
<div class="container">
    <h2 class="login-title">Sign in</h2>

    <form class="login-form" [formGroup]="signForm" (ngSubmit)="handleSubmit()">
        <div>
            <label for="name">Name </label>
            <input id="name" type="text" placeholder="Adel" name="name" required formControlName="name" />
            <span class="text-danger" *ngIf="signForm.get('name')?.invalid && signForm.get('name')?.touched">
                Name is invalid
            </span>
        </div>

        <div>
            <label for="email">Email </label>
            <input id="email" type="email" placeholder="Adel@example.com" name="email" required
                formControlName="email" />
            <span class="text-danger" *ngIf="signForm.get('email')?.invalid && signForm.get('email')?.touched">
                Email is invalid
            </span>
        </div>

        <div>
            <label for="quote">Quote</label>
            <input id="quote" type="quote" placeholder="Just do it" name="quote" required formControlName="quote" />
            <span class="text-danger" *ngIf="signForm.get('quote')?.invalid && signForm.get('quote')?.touched">
                Quote is invalid
            </span>
        </div>

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

./sign-in-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 ""