1 import { Validators } from '@angular/common';
2 import { Component, OnInit } from '@angular/core';
3 import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
4 import { Router } from '@angular/router';
6 import { AccountService } from './account.service';
9 selector: 'my-account',
10 template: require('./account.component.html'),
11 providers: [ AccountService ],
12 directives: [ REACTIVE_FORM_DIRECTIVES ]
15 export class AccountComponent implements OnInit {
17 newConfirmedPassword = '';
18 changePasswordForm: FormGroup;
19 information: string = null;
23 private accountService: AccountService,
24 private router: Router
28 this.changePasswordForm = new FormGroup({
29 'new-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
30 'new-confirmed-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
35 this.information = null;
38 if (this.newPassword !== this.newConfirmedPassword) {
39 this.error = 'The new password and the confirmed password do not correspond.';
43 this.accountService.changePassword(this.newPassword).subscribe(
44 ok => this.information = 'Password updated.',
46 err => this.error = err