1

I have a class Message, that contains an array of Addresses. Opening the page immediately querys all the pending messages. I need the Adresses to be queryed once the user opens the tab inside the message. The problem is that the Addresses and Messages are handled as 2 different objects instead of as one whole

getMessages(): void {
    let request: GetPendingMessagesRequest;
    
    this.isLoadingResultSubject.next(true);

    this.messagesQuery$.next();
    this.messagesQuery$.complete();
    this.messagesQuery$ = new Subject();

    this.queryDispatcher.dispatch(request, null, this.messagesQuery$)
      .pipe(takeUntil(this.destroy$))
      .subscribe({
        next: (getResponse: GetPendingMessagesResponse) => {
          this.messagesSubject.next(getResponse.messages);
          this.isLoadingResultSubject.next(false);
        },
        error: () => this.MessagesService.delete()
      });
  }


getAddresses(ObjektId: string | number, documentId: string | number, document: Document): void {

    let request: GetAddressesRequest;
    request = new GetAddressesRequest(
      ObjektId,
      documentId,
    );

    this.addressesQuery$.next();
    this.addressesQuery$ = new Subject();

    this.queryDispatcher.dispatch(request, null, this.addressesQuery$)
      .pipe(takeUntil(this.destroy$))
      .subscribe({next:(getaddressesResponse: GetAddressesResponse) => {
          this.addressesSubject.next(getaddressesResponse.addresses)
      }, error: () => this.AdressesService.delete()});

  }

Currently i've had 3 different results.

  1. All the information is correct but gets queryed as soon as the first Message tab is opened.
  2. Information is only correct on the last message queyed and displayed data gets changed for all the rest to match the last query.
  3. Everything works correctly except there is a button on each message to query its Addresses.
1
  • 1
    Is your question, is there a way to add an item to to an observable array after subscribing to it? The code you are showing does not look specific to Angular. You have a lot of RxJS code, but I am not sure what it's supposed to do. Why do you reassign this.addressesQuery$ = new Subject(); ? This looks suspicious. If you were subscribed to this observable, doing this would break the subscription. Commented May 5, 2023 at 15:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.