Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. import { Component, OnDestroy } from '@angular/core';
  2. import { Router } from "@angular/router";
  3. import { ChangeDetectionStrategy } from '@angular/core';
  4.  
  5. import { FormValidationService } from "../../validations/form-validation.service";
  6. import { FlashMessagesService } from 'angular2-flash-messages';
  7. import { AuthService } from '../../services/auth.service';
  8.  
  9. @Component({
  10. templateUrl: 'register.component.html',
  11. changeDetection: ChangeDetectionStrategy.OnPush
  12. })
  13. export class RegisterComponent implements OnDestroy {
  14. name: String;
  15. email: String;
  16. password: String;
  17. re_password: String;
  18. mobile:String;
  19.  
  20.  
  21. constructor(private formValidation: FormValidationService,
  22. private flash: FlashMessagesService,
  23. private auth: AuthService,
  24. private router: Router) { }
  25.  
  26.  
  27.  
  28.  
  29. registerUser(){
  30. var user = {
  31. name: this.name,
  32. email: this.email,
  33. password: this.password,
  34. re_password: this.re_password,
  35. mobile:this.mobile,
  36. }
  37.  
  38.  
  39.  
  40. if(!this.formValidation.validateEmail(this.email)){
  41. this.flash.show("Invalid email format!",{ cssClass: 'alert-danger', timeout: 3000 });
  42. return false;
  43. }
  44.  
  45. this.auth.authRegisterUser(user).subscribe(data => {
  46. if(data.success){
  47. this.flash.show("User created successfully!", { cssClass: 'alert-success', timeout: 3000 });
  48. this.router.navigate(['./admin/login']); // <-------This is the problem -------------->
  49. }else{
  50. this.flash.show(data.message, { cssClass: 'alert-success', timeout: 3000 });
  51. return false;
  52. }
  53. });
  54.  
  55. }
  56.  
  57. }
  58.  
  59. import { NgModule } from '@angular/core';
  60. import { FormsModule } from '@angular/forms';
  61. import { FlashMessagesModule } from 'angular2-flash-messages';
  62.  
  63. import { LoginComponent } from './login.component';
  64. import { RegisterComponent } from './register.component';
  65. import { AuthService } from '../../services/auth.service';
  66.  
  67.  
  68. import { AuthRoutingModule } from './auth-routing.module';
  69.  
  70. @NgModule({
  71. imports: [ AuthRoutingModule, FormsModule, FlashMessagesModule ],
  72. declarations: [
  73. LoginComponent,
  74. RegisterComponent
  75. ],
  76. providers: [AuthService],
  77. })
  78. export class AuthModule { }
  79.  
  80. import { NgModule } from '@angular/core';
  81. import { Routes, RouterModule } from '@angular/router';
  82.  
  83. import { LoginComponent } from './login.component';
  84. import { RegisterComponent } from './register.component';
  85.  
  86. const routes: Routes = [
  87. {
  88. path: '',
  89. data: {
  90. title: 'Example Pages'
  91. },
  92. children: [
  93. {
  94. path: 'login',
  95. component: LoginComponent,
  96. data: {
  97. title: 'Login Page'
  98. }
  99. },
  100. {
  101. path: 'register',
  102. component: RegisterComponent,
  103. data: {
  104. title: 'Register Page'
  105. }
  106. }
  107. ]
  108. }
  109. ];
  110.  
  111. @NgModule({
  112. imports: [RouterModule.forChild(routes)],
  113. exports: [RouterModule]
  114. })
  115. export class AuthRoutingModule {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement