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'
15 import { UserCreate } from '../../../../shared'
18 selector: 'my-signup',
19 templateUrl: './signup.component.html',
20 styleUrls: [ './signup.component.scss' ]
22 export class SignupComponent extends FormReactive implements OnInit {
31 validationMessages = {
32 'username': USER_USERNAME.MESSAGES,
33 'email': USER_EMAIL.MESSAGES,
34 'password': USER_PASSWORD.MESSAGES
38 private formBuilder: FormBuilder,
39 private router: Router,
40 private notificationsService: NotificationsService,
41 private userService: UserService
47 this.form = this.formBuilder.group({
48 username: [ '', USER_USERNAME.VALIDATORS ],
49 email: [ '', USER_EMAIL.VALIDATORS ],
50 password: [ '', USER_PASSWORD.VALIDATORS ]
53 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
63 const userCreate: UserCreate = this.form.value
65 this.userService.signup(userCreate).subscribe(
67 this.notificationsService.success('Success', `Registration for ${userCreate.username} complete.`)
68 this.router.navigate([ '/videos/list' ])
71 err => this.error = err.message