Advertisement
Guest User

Untitled

a guest
Feb 15th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { AccountApiService } from '../../services/account-api.service';
  3. import { Router } from '@angular/router';
  4. import {EditUser} from '../../../../models/EditUser';
  5.  
  6.  
  7. @Component({
  8. selector: 'account-change-password',
  9. templateUrl: './change-password.component.html',
  10. styleUrls: ['./change-password.component.css']
  11. })
  12. export class ChangePasswordComponent implements OnInit {
  13.  
  14. password = {
  15. oldPassword:null,
  16. newPassword:null,
  17. confirmPassword:null
  18. };
  19.  
  20. errorMessages: string[] = [];
  21.  
  22. public user: EditUser = new EditUser();
  23.  
  24. constructor(private accountApi: AccountApiService,
  25. private router: Router) { }
  26.  
  27. ngOnInit() {
  28. }
  29.  
  30. changePassword(changePasswordForm){
  31. this.accountApi.getUserInfo().then((data) => {
  32. this.user = new EditUser(data);
  33. this.errorMessages = [];
  34. if(changePasswordForm.form.valid){
  35. this.accountApi.changePassword(this.password).then(() => {
  36. this.router.navigate(["/account"]);
  37. }).catch((err) => {
  38. console.log(err);
  39. let error = err.error;
  40. for (let errorModel in error.modelState){
  41. this.errorMessages.push(error.modelState[errorModel]);
  42. }
  43. })
  44. }
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement