1 import { Control, ControlGroup, Validators } from '@angular/common';
2 import { Component, OnInit } from '@angular/core';
3 import { Router } from '@angular/router';
5 import { AccountService } from './account.service';
8 selector: 'my-account',
9 template: require('./account.component.html'),
10 providers: [ AccountService ]
13 export class AccountComponent implements OnInit {
14 changePasswordForm: ControlGroup;
15 information: string = null;
19 private accountService: AccountService,
20 private router: Router
24 this.changePasswordForm = new ControlGroup({
25 newPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])),
26 newConfirmedPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])),
30 changePassword(newPassword: string, newConfirmedPassword: string) {
31 this.information = null;
34 if (newPassword !== newConfirmedPassword) {
35 this.error = 'The new password and the confirmed password do not correspond.';
39 this.accountService.changePassword(newPassword).subscribe(
40 ok => this.information = 'Password updated.',
42 err => this.error = err