Created
December 6, 2018 06:37
-
-
Save oleersoy/3cdc4e2b7a74cbd9aa2739d0a7260b93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, Output, EventEmitter } from '@angular/core'; | |
| import { FormGroup, FormControl } from '@angular/forms'; | |
| @Component({ | |
| selector: 'my-login-form', | |
| template: ` | |
| <mat-card> | |
| <mat-card-title>Login</mat-card-title> | |
| <mat-card-content> | |
| <form [formGroup]="form" (ngSubmit)="submit()"> | |
| <p> | |
| <mat-form-field> | |
| <input type="text" matInput placeholder="Username" formControlName="username"> | |
| </mat-form-field> | |
| </p> | |
| <p> | |
| <mat-form-field> | |
| <input type="password" matInput placeholder="Password" formControlName="password"> | |
| </mat-form-field> | |
| </p> | |
| <p *ngIf="error" class="loginError"> | |
| {{ errorMessage }} | |
| </p> | |
| <p class="button"> | |
| <button type="submit" mat-button>Login</button> | |
| </p> | |
| </form> | |
| </mat-card-content> | |
| </mat-card> | |
| `, | |
| styles: [ | |
| ` | |
| :host { | |
| display: flex; | |
| justify-content: center; | |
| margin: 100px 0px; | |
| } | |
| .mat-form-field { | |
| width: 100%; | |
| min-width: 300px; | |
| } | |
| mat-card-title, | |
| mat-card-content { | |
| display: flex; | |
| justify-content: center; | |
| } | |
| .error { | |
| padding: 16px; | |
| width: 300px; | |
| color: white; | |
| background-color: red; | |
| } | |
| .button { | |
| display: flex; | |
| justify-content: flex-end; | |
| } | |
| `, | |
| ], | |
| }) | |
| export class LoginFormComponent { | |
| form: FormGroup = new FormGroup({ | |
| username: new FormControl(''), | |
| password: new FormControl(''), | |
| }); | |
| submit() { | |
| if (this.form.valid) { | |
| this.submitEM.emit(this.form.value); | |
| } | |
| } | |
| @Output() submitEM = new EventEmitter(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment