Guest User

Untitled

a guest
Oct 23rd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. npm install ng6-toastr-notifications --save
  2.  
  3. // set toastr
  4. showSuccess(position: any = 'top-left') {
  5. this.toastr.successToastr('This is success toast.', 'Success!', { position: position });
  6. }
  7.  
  8. import { Component, OnInit } from '@angular/core';
  9. import { Login } from '../models/login';
  10. import { LoginService } from '../service/login.service';
  11.  
  12. import {Router} from '@angular/router';
  13. import { ToastrManager } from 'ng6-toastr-notifications';
  14.  
  15. @Component({
  16. selector: 'app-login-new',
  17. templateUrl: './login-new.component.html',
  18. styleUrls: ['./login-new.component.css']
  19.  
  20.  
  21. })
  22. export class LoginNewComponent implements OnInit {
  23.  
  24.  
  25.  
  26. login = new Login('', '');
  27. wrong ='';
  28. error = '';
  29. success = '';
  30.  
  31.  
  32. constructor(private loginService: LoginService, private router: Router, public toastr: ToastrManager) {}
  33.  
  34.  
  35. // set toastr
  36. showSuccess(position: any = 'top-left') {
  37. this.toastr.successToastr('This is success toast.', 'Success!', { position: position });
  38. }
  39.  
  40.  
  41.  
  42. ngOnInit() {}
  43.  
  44.  
  45.  
  46. public loginCall(lg) {
  47. this.resetErrors();
  48. this.loginService.logdb(this.login)
  49. .subscribe(
  50. res => {
  51.  
  52. if (res.message === 'success') {
  53. // this.success = 'Login successful';
  54.  
  55. /*
  56.  
  57.  
  58. // set toastr
  59. showSuccess(position: any = 'top-left') {
  60. this.toastr.successToastr('This is success toast.', 'Success!', { position: position });
  61. }
  62.  
  63.  
  64. */
  65.  
  66. }
  67.  
  68. // Reset the form
  69. lg.reset();
  70. },
  71. err => this.error = err
  72. );
  73. }
  74.  
  75.  
  76. private resetErrors(){
  77.  
  78. this.success = '';
  79. this.wrong = '';
  80. this.error = '';
  81. }
  82.  
  83. }
  84.  
  85. <div id="theForm">
  86. <h2>The form</h2>
  87. <form #lg="ngForm" name="theForm" (submit)="loginCall(lg)">
  88. <div class="form-group">
  89. <label>Username</label>
  90. <input type="text"
  91. class="form-control"
  92. name="username"
  93. [(ngModel)]="login.username"
  94. #loginUsername="ngModel"
  95. required
  96. pattern="^[a-zA-Z]+$">
  97. <span class="help-block danger" *ngIf="loginUsername.errors?.required && loginUsername.touched">
  98. The username is required
  99. </span>
  100. <span class="help-block danger" *ngIf="loginUsername.errors?.pattern && loginUsername.touched">
  101. The username can only contain the letters a-z or A-Z
  102. </span>
  103. </div>
  104.  
  105. <div class="form-group">
  106. <label>Password</label>
  107. <input type="password"
  108. class="form-control"
  109. name="text"
  110. required
  111. [(ngModel)]="login.password"
  112. #loginPassword="ngModel">
  113. <span class="help-block danger" *ngIf="loginPassword.errors?.required && loginPassword.touched">
  114. The password is required
  115. </span>
  116. </div>
  117.  
  118. <div *ngIf="success" class="alert alert-success">{{success}}</div>
  119. <button
  120. class="btn btn-primary btn-sm"
  121. [disabled]="lg.invalid">Login Now</button>
  122. </form>
  123. </div>
  124. <br><br><br>
  125.  
  126. import { BrowserModule } from '@angular/platform-browser';
  127. import { FormsModule } from '@angular/forms';
  128.  
  129.  
  130. import { NgModule } from '@angular/core';
  131. import { RouterModule} from '@angular/router';
  132.  
  133. import { appRoutes } from './routerConfig';
  134.  
  135. import { HttpClientModule } from '@angular/common/http';
  136.  
  137. import { ToastrModule } from 'ng6-toastr-notifications';
  138.  
  139.  
  140. import { AppComponent } from './app.component';
  141.  
  142. import { LoginNewComponent } from './login-new/login-new.component';
  143.  
  144.  
  145.  
  146.  
  147. @NgModule({
  148. declarations: [
  149. AppComponent,
  150. LoginNewComponent
  151. ],
  152.  
  153. imports: [
  154. BrowserModule,
  155. HttpClientModule,
  156. FormsModule,
  157.  
  158. RouterModule,
  159. RouterModule.forRoot(appRoutes),
  160. ToastrModule.forRoot()
  161. ],
  162.  
  163. providers: [],
  164. bootstrap: [AppComponent]
  165. })
  166.  
  167.  
  168. export class AppModule { }
Add Comment
Please, Sign In to add comment