Guest User

Untitled

a guest
Dec 6th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import { Component, Output, EventEmitter } from '@angular/core';
  2. import { FormGroup, FormControl } from '@angular/forms';
  3.  
  4. @Component({
  5. selector: 'my-login-form',
  6. template: `
  7. <mat-card>
  8. <mat-card-title>Login</mat-card-title>
  9. <mat-card-content>
  10. <form [formGroup]="form" (ngSubmit)="submit()">
  11. <p>
  12. <mat-form-field>
  13. <input type="text" matInput placeholder="Username" formControlName="username">
  14. </mat-form-field>
  15. </p>
  16.  
  17. <p>
  18. <mat-form-field>
  19. <input type="password" matInput placeholder="Password" formControlName="password">
  20. </mat-form-field>
  21. </p>
  22.  
  23. <p *ngIf="error" class="loginError">
  24. {{ errorMessage }}
  25. </p>
  26.  
  27. <p class="button">
  28. <button type="submit" mat-button>Login</button>
  29. </p>
  30.  
  31. </form>
  32. </mat-card-content>
  33. </mat-card>
  34. `,
  35. styles: [
  36. `
  37. :host {
  38. display: flex;
  39. justify-content: center;
  40. margin: 100px 0px;
  41. }
  42.  
  43. .mat-form-field {
  44. width: 100%;
  45. min-width: 300px;
  46. }
  47.  
  48. mat-card-title,
  49. mat-card-content {
  50. display: flex;
  51. justify-content: center;
  52. }
  53.  
  54. .error {
  55. padding: 16px;
  56. width: 300px;
  57. color: white;
  58. background-color: red;
  59. }
  60.  
  61. .button {
  62. display: flex;
  63. justify-content: flex-end;
  64. }
  65. `,
  66. ],
  67.  
  68. })
  69. export class LoginFormComponent {
  70. form: FormGroup = new FormGroup({
  71. username: new FormControl(''),
  72. password: new FormControl(''),
  73. });
  74.  
  75. submit() {
  76. if (this.form.valid) {
  77. this.submitEM.emit(this.form.value);
  78. }
  79. }
  80.  
  81. @Output() submitEM = new EventEmitter();
  82. }
Add Comment
Please, Sign In to add comment