import { Component , Injector , ElementRef , AfterViewInit , ViewChild } from '@angular/core' ; import { Router } from '@angular/router' ; import { AccountServiceProxy , RegisterInput , RegisterOutput } from '@shared/service-proxies/service-proxies' ; import { AppComponentBase } from '@shared/component-base' ; import { LoginService } from '../login/login.service' ; import { accountModuleAnimation } from '@shared/animations/routerTransition' ; @ Component ( { templateUrl : './register.component.html' , styleUrls : [ './register.component.less' ] , animations : [ accountModuleAnimation ( ) ] } ) export class RegisterComponent extends AppComponentBase implements AfterViewInit { model : RegisterInput = new RegisterInput ( ) ; saving : boolean = false ; constructor ( injector , private _accountService , private _router , private readonly _loginService ) { super ( injector ) ; } ngAfterViewInit ( ) { } back ( ) { this . _router . navigate ( [ '/login' ] ) ; } save ( ) { this . saving = true ; this . _accountService . register ( this . model ) . finally ( ( ) => { this . saving = false ; } ) . subscribe ( ( result ) => { if ( ! result . canLogin ) { this . notify . success ( this . l ( 'SuccessfullyRegistered' ) ) ; this . _router . navigate ( [ '/login' ] ) ; return ; } this . saving = true ; this . _loginService . authenticateModel . userNameOrEmailAddress = this . model . userName ; this . _loginService . authenticateModel . password = this . model . password ; this . _loginService . authenticate ( ( ) => { this . saving = false ; } ) ; } ) ; } }