From a2d4e8b340e1a2206d61facbd685ec51eb04aa34 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Fri, 6 Sep 2024 14:14:54 +0200 Subject: [PATCH] OZG-6620 fix observable subscription --- .../postfach-mail.formservice.spec.ts | 3 ++- .../postfach-mail.formservice.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts index f5d97f2b72..c2773a73eb 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts @@ -100,7 +100,8 @@ describe('PostfachMailFormservice', () => { it('should init mail body with signatur', () => { formService.initMailBody(); - const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY)?.value; + const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value; + expect(mailBodyValue).toBe(postfachSettings.signatur); }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts index 4b68d6edc1..ad2e99d1f8 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts @@ -32,7 +32,7 @@ import { UntypedFormGroup, } from '@angular/forms'; import { ReplyOption } from 'libs/postfach-shared/src/lib/postfach.model'; -import { Observable, take } from 'rxjs'; +import { Observable, Subscription } from 'rxjs'; @Injectable() export class PostfachMailFormservice extends AbstractFormService { @@ -43,6 +43,8 @@ export class PostfachMailFormservice extends AbstractFormService { static readonly FIELD_REPLY_OPTION = 'replyOption'; static readonly FIELD_ATTACHMENTS = 'attachments'; + private loadPostfachSettingsSubscription: Subscription; + constructor( formBuilder: UntypedFormBuilder, private postfachService: PostfachService, @@ -61,12 +63,12 @@ export class PostfachMailFormservice extends AbstractFormService { } public initMailBody(): void { - this.postfachService + this.loadPostfachSettingsSubscription = this.postfachService .getSettings() - .pipe(take(1)) - .subscribe((settings: PostfachSettings) => - this.form.get(PostfachMailFormservice.FIELD_MAIL_BODY)?.setValue(settings.signatur), - ); + .subscribe((settings: PostfachSettings) => { + this.form.get(PostfachMailFormservice.FIELD_MAIL_BODY)?.setValue(settings.signatur); + this.loadPostfachSettingsSubscription.unsubscribe(); + }); } protected getPathPrefix(): string { -- GitLab