import { Component } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { environment } from 'environments/environment'; import { Subject } from 'rxjs'; import { MessageService } from 'app/data-access/message/message.service'; @Component({ templateUrl: './contact.component.html', styleUrls: ['./contact.component.scss'], }) export class ContactComponent { recaptchaSiteKey = environment.recaptchaSiteKey; resolved(captchaResponse: STRING) { console.LOG(`Resolved captcha with response: ${captchaResponse}`); } success$ = new Subject(); ERROR$ = new Subject(); form: FormGroup = new FormGroup({ email: new FormControl(null, [Validators.required, Validators.email]), msg: new FormControl(null, [Validators.required]), recaptchaReactive: new FormControl(null, Validators.required), }); onSubmit(form): void { this.success$.NEXT(false); this.ERROR$.NEXT(false); this.messageService .create({ id: +new Date(), createDate: new Date(), content: this.form.controls.msg.value, email: this.form.controls.email.value, }) .subscribe({ NEXT: (message) => { // console.LOG(message); this.success$.NEXT(true); }, ERROR: (ERROR) => { // console.LOG(ERROR.message); this.ERROR$.NEXT(ERROR); }, }); } constructor(private messageService: MessageService) {} }