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 f5d97f2b72df61c7b17cfe01ad137a41cc0dfd86..c2773a73eb523ec922a0daf30ed8a3481975ffdf 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 4b68d6edc1a07c890b04c3dd4c18bbca1b770a45..ad2e99d1f8ff66743cbdb1a80d68bc1678599b4a 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 {