Array behavior subjects are used to store multiple values and emit new

When running the code snippet provided, the result displayed is [object object] instead of the expected [{a,b},{b,c}].

// Service
bData : BehaviorSubject<any[]> =  new BehaviorSubject<any[]>([]);

bDataSubject = this.bData.asObservable(); 

// Component: 
 
data = [{a,b},{b,c}];
 
this.service.bData.next((this.data));
  
this.service.bData.subscribe(value =>
 console.log("value changed: " + value)
);

Answer №1

Make sure to name it correctly:

userDataSubject: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
userData$ = this.userData.asObservable();

// to send data
userDataSubject.next(this.data);

// to retrieve data
this.service.userData$.subscribe(value =>
 console.log("value updated: " + value)
);

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

Creating a see-through effect in Three.js with React Fiber

I'm currently working with react fiber and struggling to make the background of my child scene transparent. Below is my root component containing the main Canvas element: export const Splash = () => { const { intensity, distance, colo ...

Scouring the Active Directory with AngularJS

I am still fairly new to working with Angular, and I have a web application that requires users to input names and locations. One common issue raised by users is the inability to search for people using active directory. Is there a way for me to implemen ...

When incorporating a new group in a three.js Scene, the older object groups are automatically eliminated

Currently, I am developing a visual components designer that includes a functionality to group objects together under a specific name. When any of the grouped objects is selected, a red box should be displayed around them. However, I am facing an issue wh ...

Is it feasible to invoke a method without any arguments on this basic subscription?

A BRIEF SUMMARY Implementing an observable in my code, I strive for maintaining cleanliness and efficiency by utilizing the detectChanges() method to update *ngIf= in the HTML. QUERY Is there a way to invoke the detectChanges() method within subscribe() ...

Utilizing Google Sheets as a secure, read-only database for Angular applications without the need to make the sheet accessible to the

Seeking a way to utilize Google Sheets document as a read-only database for my Angular application, I have attempted various methods. However, the challenge with all these approaches is that they necessitate public sharing of the Sheet (accessible to anyon ...

Updating token (JWT) using interceptor in Angular 6

At first, I had a function that checked for the existence of a token and if it wasn't present, redirected the user to the login page. Now, I need to incorporate the logic of token refreshing when it expires using a refresh token. However, I'm enc ...

Is it possible to devise a universal click handler in TypeScript that will consistently execute after all other click handlers?

In my ReactJS based application written in TypeScript, we have implemented various click handlers. Different teams contribute to the application and can add their own handlers as well. The challenge we face is ensuring that a specific global click handler ...

The technique for accessing nested key-value pairs in a JSON object within an Angular application

After receiving the response from the backend, I have retrieved a nested hash map structure where one hash map is nested within another: hmap.put(l,hmaps); //hmap within hmap When returning the response to the frontend, I am using the ResponseEntity meth ...

Experiencing constant errors with axios requests in my MERN Stack project using a Typescript Webpack setup

Hey there, I'm in need of some help! I've been working on a MERN Stack project and have set up Webpack and Babel from scratch on the frontend. However, every time I send a request to my Node Server, I keep getting an error message back. Can anyon ...

Exploring how to set dropdown menu width for Angular2 mat-select options

Currently, I am using the angular2 mat-select control and facing an issue with the width and position of its dropdown list menu. By default, it is wider and overflows the element on both sides by a few pixels. I have not found any option for adjusting the ...

Creating a data type restricted to utilizing property names exclusively from a specified string union:

I have a specific Enum: enum MyEnum { optionOne = 0, optionTwo = 1, optionThree = 2, optionFour = 3, } and a related Type: export type EnumNamesList = keyof typeof MyEnum; I am looking to create a type similar to this: export type EnumDataTypes = ...

Is there a way to retrieve the zoom level in Highmaps and are there any events related to zooming in Highmaps

Is there a way to trigger a zoom event in Highmaps? Furthermore, how can the current zoom level of the map be retrieved? Adjusting the zoom level is straightforward, but extracting it proves to be more challenging. After exploring the API documentation, ...

Guide for transforming a list of items into nested structures based on a key comparison

Objective: The goal is to organize the list of objects into a nested object structure based on their parent values. Here is the json data provided: "data": [ { "id": "coding-825x500", "source": { "information": { "fileid ...

Understanding 'this' in ChartJS within an Angular application

Here is my event handler for chartJS in Angular that I created: legend: { onClick: this.toggleLegendClickHandler After changing the text of the y scale title, I need to update the chart. I am looking to accomplish this by calling this._chart.cha ...

Vue3 TypeScript may potentially have an object that is 'undefined'

This piece of code is Vue3 with TypeScript-based. export interface TenantDto { uuid: string; name: string; } export const useTenantStore = defineStore('tenant', { state: () => ({ tenants: [], }), actions: { setMyTenants: (pa ...

Having difficulty grasping the significance of the data received from the API response

Currently, as I am working on my personal Portfolio for a Web Developer course, I have encountered an issue with correctly implementing my API to retrieve information from the database. Previously, I faced no problem when using a .json file, but now, I am ...

Utilize Angular Guards and RxJS to coordinate the flow of data between parent and child Guards. Ensure that the Child Guard waits for the parent

Is it possible to validate data in a child component's guard that was fetched from the parent's guard? I have parent components with employees and used a guard to fetch data from the server. Now, I want to verify this data in the child component& ...

Developing a hybrid application with .Net Core and Angular 2 is an achievable task

https://i.sstatic.net/hWlHp.png Currently, I am working on developing an application that involves utilizing .net core and angular2 technologies. Is it possible to integrate an angular component within Razor view Pages seamlessly? ...

Customizing the styling of buttons in Highcharts is disabled when in full screen mode

I've integrated highcharts into my Angular application and included a custom button inside the chart to navigate users to another page. However, I encountered an issue when trying to fullscreen the chart using the export menu. The position of the cus ...

Issue encountered while creating Next.js 13.4 application: The type 'ResolvingMetadata | undefined' does not meet the requirement of 'ResolvingMetadata'

I'm currently working on dynamically generating metadata for my Next.js 13.4 application using this code snippet: export async function generateMetadata( { params, searchParams }: Props, ) { try { // extract the route parameters ...