Changing the child component input in Angular's deep cloning cannot be reflected on the user interface

I am currently working on a parent-child component setup. Within the parent component, I have a

BehaviourSubject<SomeObject[]>()
.

export interface SomeObject(){
field: number;
...
editable: boolean
}

Before passing the object to the child component, I need to filter it so that the input value appears as follows:

childInputData = parentBehaviourSubject.value.filter(x=>...);

In the child component UI, there is an edit icon that is visible only if the field editable = false. When this icon is clicked, it should change editable = true and allow certain fields to be edited. My issue arises when trying to pass a cloned array as the child input. When I make the following change:

childInputData = _.cloneDeep(parentBehaviourSubject.value.filter(x=>...));

The UI edit icon no longer responds to clicks. I am unsure of what I am missing here. Can anyone provide insight into why this might be happening?

Answer №1

Is there a specific reason for applying the filter(...) function on an object? This method is typically used for arrays. By calling .value on the behavior subject, you are essentially retrieving the current value and disregarding any future values that may be emitted.

If you intend to pass the current value to the child component each time, it is advisable to pipe the value and subscribe to it (using the async pipe).

The code snippet below generates an observable that contains copies of each emitted value from the parentBehaviourSubject:

childInputData$ = parentBehaviourSubject.pipe(map( val => _.cloneDeep(val) );

To pass this value to your child in the HTML, you can utilize the following code:

<child-component [childData]="childInputData$ | async">
...

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

Validation failures frequently occur in the typeahead feature of Angular 2 when using Bootstrap 4, despite a value being selected

I need to implement an auto-complete feature using Bootstrap Typeahead in a form I am currently working on. <input [(ngModel)]="model.brand" [typeahead]="model.brands" ng-model-options="{'updateOn': 'blur'}" (typeaheadOnSele ...

Example showcasing the functionality of the react-custom-scrollbars package in a TypeScript React application

In my TypeScript React project, I am struggling to set up the react-custom-scrollbars package successfully. Despite consulting the examples provided in the GitHub repository, I have not been able to get it working. Can someone share a functional example ...

A guide to updating a table in Angular using an API response

My form allows me to select events from a drop-down list and choose a date. Depending on the selected date, it retrieves the number of events that occurred on that specific date. If I select an event and a date where events took place, the "All Events" sec ...

Is there a way to combine multiple array objects by comparing just one distinct element?

Is there a way to combine these two arrays into one? array1 = [ { image: 'image1', title: 'title1' }, { image: 'image2', title: 'title2' }, { image: 'image3', title: 'title3' }, ]; array2 = ...

What steps can I take to prevent encountering a Typescript Error (TS2345) within the StatePropertyAccessor of the Microsoft Bot Framework while setting a property?

During the process of constructing a bot in Typescript, I encountered TS2345 error with Typescript version 3.7.2. This error is causing issues when attempting to create properties dynamically, even if they are undefined, or referencing them in the statePro ...

Having difficulty installing node-sass in an Angular project

Having downloaded a repository from an existing Angular project, I proceeded to run sudo npm install within the project. While all packages were successfully installed, the node-sass package continued to cause issues. Upon completion of the installation ...

Preventing memory leaks in unmounted components: A guide

Currently, I am facing an issue while fetching and inserting data using axios in my useState hook. The fetched data needs to be stored as an array, but unfortunately, I encountered a memory leak error. I have tried various solutions including using clean u ...

Angular's ngClass directive failed to be applied correctly

I am currently experimenting with the use of [ngClass] in Angular and it appears that it is not being applied as expected. Interestingly, [ngStyle] for similar CSS styles is working without any issues. What could I be doing wrong in this scenario? There ar ...

Convert a string into a component

I need to generate a routing file in my Angular Project where all path and component names are stored in a database. The components will be selected based on the user's login rights. Currently, I am looking to create a route array in the routing mod ...

"Utilizing the Power of Typescript with Koa-Router and Passport for a

As a beginner in Typescript, I am facing challenges while trying to integrate koa-router and koa-passport. I have installed all the necessary @types\ packages. import Koa from "koa"; import Route from "koa-router"; import passport from "koa-passport" ...

Unable to access setRowData() in AgGrid/Angular 2 leads to rendering of the grid without displaying any rowData

Resolved I think my solution is temporarily fixed and it reveals that I may have set up my mongoose model incorrectly. The answer provided did assist me in solving my issue, but ultimately the reason for the empty data rows was due to incorrect identifier ...

Angular Refresh Tokens

I've developed a service for calling APIs from my Angular application. Within this service, I've defined the ROOT_URL and TOKEN variables and assigned values to them. Following the declaration, there are several GET methods to access APIs using ...

Table with dynamic rows containing different number of sub-sections

Looking to utilize the mat-table directives, such as *matRowDef and multiTemplateDataRows in order to construct a table with dynamic sub-rows for each main row. To illustrate, consider the following interface: interface ReportCard { student: string; r ...

What is the process of converting the Object type returned from an Observable to an array of objects in Angular?

When utilizing the GET method to retrieve information, I have encountered a problem. Here is the code snippet: constructor(private http: HttpClient) { } items: Item[]; stuff: any[]; ngOnInit() { const url = ...; this.http.get(url) .subscribe(nex ...

What is the best way to send multiple data using GetServerSideProps?

I have a challenge where I need to pass multiple sets of sanity data into a component, but I am restricted to using getServerSideProps only once. How can I work around this limitation to include more than one set of sanity data? pages > members.tsx exp ...

Creating a custom type in Typescript using a function for testing purposes

I have been exploring ways to limit my search capabilities to specific criteria. Let's say I have a model and some data like the following: interface UserModel { _id: string; username: string; party: UserPartyModel; } interface UserParty ...

What is causing the error message "Module '@reduxjs/toolkit' or its type declarations are not found" to appear?

Although I have a good understanding of React-Redux, I decided to delve into TypeScript for further practice. Following the recommended approach from the react-redux team, I created a new project using the TS template: "npx degit reduxjs/redux-templa ...

Upon upgrading to Angular 8, the function this._delegate.setNgStyle is not recognized

Following the update of my project from Angular 7 to Angular 8 and resolving all errors caused by breaking changes, I am encountering a new issue: <div fxFill ngStyle.xs="overflow:auto"> This line is resulting in the following error: ERROR Type ...

Is there a way for me to showcase a particular PDF file from an S3 bucket using a custom URL that corresponds to the object's name

Currently, I have a collection of PDFs stored on S3 and am in the process of developing an app that requires me to display these PDFs based on their object names. For instance, there is a PDF named "photosynthesis 1.pdf" located in the biology/ folder, and ...

Module not found in Typescript

Filter.ts, mustache.js and redux.3.5.2.js are all located in the same directory (/Scripts). The code snippet within Filter.ts is as follows: ///<reference path="./typings/mustache.d.ts" /> import Mustache = require("mustache"); import Redux = requir ...