import { Component , OnInit } from '@angular/core' ; import { FormBuilder , FormGroup , Validators } from '@angular/forms' ; import { Router } from '@angular/router' ; import { ToastrService } from 'ngx-toastr' ; import { UserOperationClaim } from 'src/app/models/user/userOperationClaim' ; import { AuthService } from 'src/app/services/auth/auth.service' ; import { LocalStorageService } from 'src/app/services/localStorage/local-storage.service' ; import { UserService } from 'src/app/services/user/user.service' ; @ Component ( { selector : 'app-register' , templateUrl : './register.component.html' , styleUrls : [ './register.component.css' ] , } ) export class RegisterComponent implements OnInit { registerForm : FormGroup ; constructor ( private formBuilder , private toastrService , private authService , private router ) { } ngOnInit ( ) { this . createRegisterForm ( ) ; } createRegisterForm ( ) { this . registerForm = this . formBuilder . group ( { email : [ '' , Validators . required ] , password : [ '' , Validators . required ] , firstName : [ '' , Validators . required ] , lastName : [ '' , Validators . required ] , } ) ; } register ( ) { if ( this . registerForm . valid ) { let registerModel = Object . assign ( { } , this . registerForm . value ) ; this . authService . register ( registerModel ) . subscribe ( ( response ) => { this . toastrService . info ( 'Kayıt Oluşturuldu' , 'Başarılı' ) ; this . router . navigate ( [ 'login' ] ) ; } , ( responseError ) => { this . toastrService . error ( responseError . error ) ; } ) ; } else { this . toastrService . error ( 'Formunuz Eksik' , 'Dikkat' ) ; } } }