Combining the output of two Observables through the CombineLatest method to generate a

I possess two separate collections of information:

Data Model: taxControlReference

 [
    {
        "providerId": "HE",
        "taxTables": {
            "STAT": [
                1
            ]
        }
    },
    {
        "providerId": "REMC",
        "taxTables": {
            "STAT": [
                1
            ]
        }
    },
    {
        "providerId": "WBLUE",
        "taxTables": {
            "STAT": [
                1
            ]
        }
    }
]

Data Model: taxControl

[
    {
        "taxTypeId": "FED",
        "taxIndustryDescription": "Federal",
        "taxIndustryLabel": "Federal",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    },
    {
        "taxTypeId": "FRAN",
        "taxIndustryDescription": "Franchise",
        "taxIndustryLabel": "Franchise",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    },
    {
        "taxTypeId": "STAT",
        "taxIndustryDescription": "State",
        "taxIndustryLabel": "State",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    },
    {
        "taxTypeId": "CNTY",
        "taxIndustryDescription": "County",
        "taxIndustryLabel": "County",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    },
    {
        "taxTypeId": "TOWN",
        "taxIndustryDescription": "City",
        "taxIndustryLabel": "City",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    },
    {
        "taxTypeId": "SCHL",
        "taxIndustryDescription": "School",
        "taxIndustryLabel": "School",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    }
]

Within the taxControlReference, each key within the taxTables corresponds with a taxTypeId in the taxControl model.

To derive an output based on this data, I am aiming for a structure as follows:

Array<{taxTypeId: string, taxIndustryDescription, options: taxTablesKey[]}>

The process involves the utilization of observables:

// taxControl$ and taxControlReference$ serve as the observables returning data from the aforementioned models
observable$ = CombineLatest([taxControl$, taxControlReference$]).pipe(
    // At this stage, difficulty arises when attempting to map out just the taxControl$, resulting in the final object in the array being repeated multiple times corresponding to the array's length of objects 
)

Answer №1

I'm having trouble understanding some aspects of your issue. Let me point out a few things:

taxControlData$: Observable<any> = combineLatest([
  this.taxControlQuery.taxControlService$, 
  this.taxControlReferenceQuery.taxControlReferenceService$
]).pipe(
  map( ([taxControls, taxTables] : [TaxControl[], TaxTable[]]) => {
    // taxControls is an array (TaxControl[]) 
    // Setting options on an array seems unusual - are you sure about this?
    taxControls.options = taxTables.map(
      // It's unclear what taxTables represents here based on the provided model
      taxTables => taxTables.map(
        // This results in an array of boolean values, how will these be used?
        options => options === taxTables.taxTypeId
      )
    );
    // Remember to return something inside the RxJS map function,
    // Otherwise, it'll result in a stream of void values.
    return /* ??? */ 
  })
)

In general, I'm unsure of the desired outcome. You mentioned wanting the output to resemble:

[
    taxIndustryDescription<string>,
    options<taxTables[]>
]

Is your data always singleton arrays? How would the output change if taxControlReferenceService$ emits new data?

[
   {
        "taxTypeId": "STAT",
        "taxIndustryDescription": "State",
        "taxIndustryLabel": "State",
        "taxControlReferenceCounter": 1,
        "transactionOn": null
    },...
]

What should the updated output look like now?

Update

We still need clarity on your objective. Providing example output matching given input might help. Can you show how the provided data translates into expected output?

This code snippet aims to generate an array following the format you described. It pairs off values from the input:

taxControlData$: Observable<any> = combineLatest([
  this.taxControlQuery.taxControlService$, 
  this.taxControlReferenceQuery.taxControlReferenceService$
]).pipe(
  map( ([taxControls, taxTables] : [TaxControl[], TaxTable[]]) => {
    const output = new Array<any>();
    for(let i = 0; i < taxControls.length; i++){
      output.push({
        taxTypeId: taxControls[i].taxTypeId,
        taxIndustryDescription: taxTables[i].taxIndustryDescription,
        options: [{/*?taxTablesKey?*/},{/*?taxTablesKey?*/},{/*?taxTablesKey?*/}]
      })
    }
    return output;
  })
)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Testing the selection of dropdown values in Angular2 using unit tests

I have a dropdown menu for selecting countries. It defaults to a pre-selected value, and when the user changes it, they are redirected to the corresponding country page. However, I am facing an issue while trying to unit test the default value in the sele ...

Connecting ADFS to your Angular 2 project

I need to integrate ADFS with an Angular 2 Project. Despite it being an older technology, we specifically require ADFS for this project. After researching, I came across a similar question on Stack Overflow discussing On-Prem ADFS and suggesting the use o ...

Angular 2+: Harnessing the Power of Web Tokens

After sending a POST request to the backend REST API through a login component, I receive an x-auth token in the response headers. What is the best way to retrieve and save this token for using it in all subsequent API requests throughout the user's l ...

Debugging in Next.js and Sanity.io: "Client Components do not support async/await yet, only Server Components."

I am a beginner working on creating a website and e-commerce store using React, Next 14, Typescript, and Sanity as the CMS. I have been following a tutorial available at https://www.youtube.com/watch?v=g2sE034SGjw&t. Encountering the following error: ...

What is the best way to implement Angular 2 slash routes in conjunction with Node Express?

I have defined some routes in my App component: @routeConfig([ { path:'login', name: 'Login', component: Login }} Additionally, I have a basic node express loader set up: var express = require('express'); var ...

In Typescript, an index signature parameter can only be of type 'string' or 'number'

I'm facing an issue with a generic type that defaults to string: interface EntityState<typeOfID = string> { entities: { [ id: typeOfID]: any }; } The error I receive is: An index signature parameter type must be either 'string' or ...

Utilizing Angular to augment existing items in local storage

Hey everyone, I'm facing an issue with localStorage that I can't seem to figure out. I have a form where the first step collects name and gender, and the second step asks for weight and height. The data from step 1 is saved in localStorage, but ...

The issue with Angular 2's Ng style is that it does not properly remove the old style when there is a change

I am currently experiencing an issue within my project. When assigning an object to ngStyle in a div, the problem arises where ngStyle does not clear the style properties from the previous object when there is a change in the object. It should ideally rem ...

Angular 5 dynamically updates its model after the completion of events

The issue at hand Currently, I am working with angular 5 and have created a component that consists of 3 controls. <ss-multiselect-dropdown id="type" formControlName="type" (ngModelChange)="onChange('type')"></ss-multiselect-dropdown&g ...

The name 'Map' cannot be located. Is it necessary to alter your target library?

After running the command tsc app.ts, an error occurs showing: Error TS2583: 'Map' is not recognized. Should the target library be changed? Consider updating the lib compiler option to es2015 or newer. I want the code to compile without any issu ...

Dropdown with grouped options in Angular PrimeNG - displaying data other than the default label/value pair

Hello there, I've encountered some difficulties with the dropdown menu, specifically when it comes to organizing by groups. Initially, I faced challenges understanding the specific format required for the array used in options to populate the dropdow ...

Creating consistency in tab spacing within a text area

At the moment, I am utilizing an HTML textarea attribute to collect input from users and then displaying that text back to them formatted. However, there seems to be an issue with how it handles tabs. For instance, when attempting to input the following: ...

Warning from Google Chrome: Ensure password forms include optional hidden username fields for improved accessibility

Upon visiting the "reset password" route of my single-page application and checking the Chrome browser console, I am presented with a warning message: [DOM] Password forms should contain (optionally hidden) username fields for accessibility: (More info: g ...

Angular Compilation Errors Caused by Component Inheritance

My parent Component is structured like this: import { Component} from '@angular/core'; @Component({ selector: 'app-main-parent', template: '', }) export class ParentComponent { constructor(protected service) { ...

I'm interested in retrieving just the ID specifically when filtering in Angular

This is the filter I have in my service.components.ts this.pijatService .getById(this.id) .pipe(first()) .subscribe((x: any) => { this.form.patchValue(x); console.log(x); this.form.value.nomor_telepo ...

Does anybody have information on the Namespace 'global.Express' not having the 'Multer' member exported?

While attempting to set up an endpoint to send a zip file, I keep encountering the following error: ERROR in ./apps/api/src/app/ingestion/ingestion.controller.ts:46:35 TS2694: Namespace 'global.Express' has no exported member 'Multer'. ...

The data in ag Grid does not display until all grid events have been completed

After setting the rowData in the onGridReady function, I noticed that the data does not display until all events are completed. I also attempted using the firstCellrendered event, but unfortunately, it did not resolve the issue. OnGridReady(){ this.r ...

Exploring the Concept of Template Element Recursion in Angular JS 2

In my Angular 2 project, I encountered a situation where I needed to iterate through ngFor based on child elements. My component should be able to render a list based on the input provided. Here is an example of the data structure: [ { name: 'ABC ...

Error TRPCClient: The unexpected presence of the token "'<'", ""<!DOCTYPE "... invalidates the JSON format within Next.JS

Encountering an error in the authentication call back page: TRPCClientError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON in Next.JS. The issue occurs in src/app/auth-callback/page.tsx and here's the relevant code ...

Ecommerce Template for Next.js

I am new to the world of web development and I have a project involving customizing a Next.js ecommerce template. Since I'm still learning programming, I would appreciate a simple summary of the steps I need to take in order to achieve this. The speci ...