1 import { Component, OnInit } from '@angular/core';
2 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3 import { Router } from '@angular/router';
5 import { NotificationsService } from 'angular2-notifications';
7 import { AuthService } from '../core';
17 selector: 'my-signup',
18 templateUrl: './signup.component.html'
20 export class SignupComponent extends FormReactive implements OnInit {
29 validationMessages = {
30 'username': USER_USERNAME.MESSAGES,
31 'email': USER_EMAIL.MESSAGES,
32 'password': USER_PASSWORD.MESSAGES,
36 private formBuilder: FormBuilder,
37 private router: Router,
38 private notificationsService: NotificationsService,
39 private userService: UserService
45 this.form = this.formBuilder.group({
46 username: [ '', USER_USERNAME.VALIDATORS ],
47 email: [ '', USER_EMAIL.VALIDATORS ],
48 password: [ '', USER_PASSWORD.VALIDATORS ],
51 this.form.valueChanges.subscribe(data => this.onValueChanged(data));
61 const { username, password, email } = this.form.value;
63 this.userService.signup(username, password, email).subscribe(
65 this.notificationsService.success('Success', `Registration for ${username} complete.`);
66 this.router.navigate([ '/videos/list' ]);
69 err => this.error = err.text