The quantity of elements remains constant in the EventEmitter

The Grid component is structured as follows:

export class GridComponent {
    @Output('modelChanged') modelChangedEmitter = new EventEmitter();

    private valueChanged(newValue: any, item: Object, prop: string) {
        item[prop] = newValue;
        this.emitChangedData();
    }

    private deleteItem() {
        this.data = this.data.filter(function (e) {
            return e !== this.toBeDeletedItem;
        });
        this.emitChangedData();
    }

     private emitChangedData() {
        this.modelChangedEmitter.emit({
            data: this.data
        });
     }

}

When a value is changed or deleted, the EventEmitter sends the current data state to the container component. The value changes are properly transmitted to the container component, but if an element is filtered out (as done in the Grid Component), the emitted data still contains the same number of items.

This is how the container component is initialized:

<grid [title]="'This is the grid title'" (modelChanged)="dataChanged(data)"></grid>

What could be causing this issue?

Answer №1

Replace () => with function ()

private removeItem() {
    this.data = this.data.filter(function(e) {
        return e !== this.toBeRemovedItem;
    });
    this.emitModifiedData();
}

to make sure this. continues to reference the current class.

adjust based on feedback

<grid (modelChanged)="updateData($event)"></grid> 

instead of

<grid (modelChanged)="updateData(data)"></grid>

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

Tips for validating and narrowing a type in TypeScript using isNull instead of isNonNullable

I want to implement a universal type guard for entities returned from an API. The goal is to handle any null | undefined values by throwing an HttpStatus.NOT_FOUND error. Initially, I tried the following approach: export const entityOr404 = <T>(entit ...

Extend mat-table with 3 expanding columns and 1 clickable column

Is there a way to add different click events for specific columns of an Angular Material Table? Specifically, I would like the left column (Blue/LP) to trigger a click event that passes the LP value, while the right column triggers an expand action. Curren ...

The Heart of the Publisher-Subscriber Design Paradigm

After reading various online articles on the Publisher-Subscriber pattern, I have found that many include unnecessary domain-specific components or unreliable information inconsistent with OOP standards. I am seeking the most basic and abstract explanatio ...

Mapping the changes in the checkbox of a material tree node

Check out this demo on StackBlitz: Tree View I'm having issues with the tree not displaying as desired. I would like it to look like this: Manager Sublist Manager 1 Manager 2 Manager 3 Could you please review and provide some advic ...

The name 'CallSite' is missing from the Error stack trace when working with Node.js and TypeScript

I am facing an issue with the following code: Error.prepareStackTrace = function ( error: Error, stack: Array<CallSite>, ) { return self.parse(fiber, error, stack) } I am attempting to import the CallSite, but it seems like it cannot be found ...

An Unexpected ER_BAD_FIELD_ERROR in Loopback 4

I encountered an unusual error: Unhandled error in GET /managers: 500 Error: ER_BAD_FIELD_ERROR: Unknown column 'role_id' in 'field list' at Query.Sequence._packetToError (/Users/xxxx/node_modules/mysql/lib/protocol/se ...

Angular Forms testing with Karma Unit Testing is throwing the following error message: ""

Here is a test case scenario: fit('When the Address field is left blank, it should be marked as Invalid', () => { component.basicBookFormGroup.patchValue({ bookName: 'My Site Name', bookOrg: 'Org ...

Recording changes in SVG size in Angular 2

I am aiming to create an SVG canvas within an Angular 2 template that automatically scales with its parent element and triggers a redraw method when its size changes. While using the onresize property, I successfully receive events but encounter difficult ...

Is there a specific reason why the app.module.ts file is not generated when I initialize a new Angular application?

Each time I attempt to create a fresh Angular app with the ng new "your-app-name" command, the project structure does not include the app.module.ts file and there is no prompt from the Angular CLI regarding whether to add routing. Additionally, in the main ...

Ways to fix the perpetual cycle in adal-angular4 following authentication redirect

I have been working on an Angular 8 application that utilizes Microsoft Azure Active Directory authentication with adal-angular4. I've successfully set up an ASP.NET Core API linked to a client app on Azure. To configure Active Directory, I referred ...

Tips on making Angular Material form controls dynamic

I am currently facing a dilemma where I am unsure how to dynamically set form controls. Below is the code snippet that illustrates my issue: <div [formGroup]="form"> <mat-form-field appearance="legacy"> <input matI ...

Avoid obtaining cookies within the TRPC environment

Recently, I've been setting up TRPC with Next.js and attempting to implement server-side rendering where I fetch user data before the page loads using the trpc.useQuery hook. However, I'm facing an issue where I cannot access the JWT token cookie ...

What is the most recent stable version of Angular recommended for utilizing ui-bootstrap?

I've been working on updating an older angular application and I'm interested in incorporating ui bootstrap for more advanced features. However, the current version of Angular used is 1.2.18 and any attempt to upgrade it to a higher version resul ...

Error: Trying to access 'items' property of an undefined variable leads to a TypeError

I am currently working on creating a webpage with Angular 8 that fetches data from a REST API in JSON format by passing the request ID. My goal is to display this data in an HTML table that I have created. However, I encountered the following error: Typ ...

Modifying content directly within the Angular Material data table

Can you create an Angular Material data table with inline editing capability? Specifically, is it possible to have cells in certain columns be editable as soon as the table loads (similar to the Editable Email column fields shown in the image below)? If th ...

Can you guide me on utilizing the drag and drop functionality in Angular 8 CDK to merge two cards together?

My current challenge involves attempting to drag one card over another card in order to effectively "merge" or "combine" them, similar to the action of dragging an image onto a folder on a desktop. Despite utilizing HTML5 native drag and drop functionalit ...

Router-outlet @input decorator experiencing issues with multiple components

Within my router module, I have a route set up for /dashboard. This route includes multiple components: a parent component and several child components. The data I am trying to pass (an array of objects called tablesPanorama) is being sent from the parent ...

What is the process for obtaining a literal type from a class property when the class is passed as an argument, in order to use it as a computed property

Just a moment ago I posted this question on Stack Overflow, and now I have a follow-up query :) Take a look at this code snippet: import { ClassConstructor } from "class-transformer"; import { useQuery as useApolloQuery } from "@apollo/clie ...

Encountering an error of TypeError while attempting to generate a new GraphQL

Currently using Apollo-Server/TypeScript with graphql-tool's makeExecutableSchema() to set up schema/directives. Encountering an error while attempting to add a basic GraphQL Directive: TypeError: Class constructor SchemaDirectiveVisitor cannot be in ...

Can errors be selectively ignored in Angular's global error handler based on certain conditions?

I am currently facing a situation where I need to handle errors when calling an API to save data, either manually or automatically. For manual saves, I have implemented an Angular global error handler to display the error message if the save fails. Howeve ...