import { Component , ChangeDetectionStrategy } from '@angular/core' ; import { FormControl } from '@angular/forms' ; import { Router } from '@angular/router' ; import { AuthService } from '../auth.service' ; import { BehaviorSubject } from 'rxjs' ; @ Component ( { selector : 'app-sign-up' , templateUrl : './sign-up.component.html' , styleUrls : [ './sign-up.component.css' ] , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class SignUpComponent { email = new FormControl ( '' ) ; fullName = new FormControl ( '' ) ; private busy_ = new BehaviorSubject ( false ) ; public busy = this . busy_ . asObservable ( ) ; private errorMessage_ = new BehaviorSubject ( '' ) ; public errorMessage = this . errorMessage_ . asObservable ( ) ; constructor ( private router , private auth ) { } public async signup ( ) { this . errorMessage_ . next ( '' ) ; this . busy_ . next ( true ) ; try { await this . auth . signUp ( this . email . value , this . fullName . value ) ; await this . auth . signIn ( this . email . value ) ; this . router . navigate ( [ '/enter-secret-code' ] ) ; } catch ( err ) { console . log ( err ) ; this . errorMessage_ . next ( err . message || err ) ; } finally { this . busy_ . next ( false ) ; } } }