Angular 8 is throwing an error due to exceeding the maximum call stack size

Currently, I am facing an issue with my 2 dropdown lists. I am binding product data to them. In the first dropdown, I have product codes and in the second dropdown, I have product names. The goal is that when a user selects a product code from the first dropdown, the second dropdown should automatically select the corresponding product name. Everything works fine with the first dropdown. However, when I try to implement the same logic for the second dropdown, I encounter an error.

Error: Maximum call stack size exceeded.

 <div class="col-md-9">
 <select id="Code" class="form-control" placeholder="Code"
(ngModelChange)="onCodeChange()" formControlName="sku" required>
 <option [value]="''">Select Code</option>  
 <option [value]="product.sku"
  *ngFor="let product of productData">   
  {{product.sku}}
  </option>
 </select>                                                      
  </div>

<div class="col-md-9">
 <select id="name" class="form-control" placeholder="Name"
 (ngModelChange)="onProductChange()" formControlName="productName" required>
  <option [value]="''">Select Name</option>
 <option [value]="product.productName" 
 *ngFor="let product of productData">
 {{product.productName}}
 </option>
</select>
</div>

onCodeChange(): void {
         const stock = (this.sharedService.where(this.productData, 'sku', this.stockForm.controls.sku.value) || {}) as any;
         this.stockForm.controls.productName.reset( stock.productName);

    }
    onProductChange(): void {
        const stock = (this.sharedService.where(this.productData, 'productName', this.stockForm.controls.productName.value) || {}) as any;
        this.stockForm.controls.sku.reset( stock.sku);

    }

The 'productData' variable holds information related to products. Here, the sku represents the product code.

Answer №1

Looks like you may have stumbled upon an infinite loop situation.

When the user selects a sku, it triggers the ngModelChange event, which in turn calls the onCodeChange() function.

The onCodeChange function resets the productName control, causing another ngModelChange event to be triggered, but this time for the product control and its associated onProductChange function.

The onProductChange function then resets the sku, leading to the invocation of the onCodeChange function once again.

This cycle repeats indefinitely, with onCodeChange indirectly calling onProductChange and vice versa.

To resolve this issue, consider moving the reset code to an onselection event or a similar alternative.

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

Error with the Exchange Web Services SMTP address

Before delving into all the details, please review the edit below: Dilemma I'm facing an issue while attempting to access my personal calendar through Exchange Web Services on SharePoint 2010. It was functioning fine earlier today and I haven&apos ...

The Telerik ListView's RadListViewItemDragDropEventArgs shows a blank DestinationHtmlElement

When implementing drag and drop with a Telerik RadListView using ASP.NET controls, I encountered an issue where the server event (ItemDrop) EventArgs did not contain data specifying where the item was dropped. Specifically, I needed information from the De ...

Angular2 Error -- The server is unable to locate the resource at http://localhost:1595/angular2/http

Struggling with getting my first Angular2 app up and running. I keep encountering the error message "The server has not found http://localhost/angular2/http". All other Angular elements are functioning correctly, so it appears to be a problem specific to ...

Ignore a directory during TypeScript compilation

When writing code in Atom, the use of tsconfig.json to include and exclude folders is essential. For optimal intellisense functionality, the node_modules folder must be included. However, when compiling to js, the node_modules should not be compiled. To ac ...

What is the best way to modify the color of a table cell in Typescript with *ngFor loop?

I have an image located at the following link: https://i.sstatic.net/rxDQT.png My goal is to have cells with different colors, where main action=1 results in a green cell and action=0 results in a red cell. Below is the HTML code I am working with: & ...

"Frustrating experience: Attempting to initiate a new project

After creating a new project using angular-cli (angular 5), I encountered a failure during the startup process (even though it was working fine last week): ERROR in C:/Users/Dev/CoursAngular/jsjobs/src/main.ts Module build failed: Error: C:\Users&bso ...

Utilizing a single menu page across various pages in IONIC 4

My challenge in Ionic 4 involves creating a menu page and then calling this page within various other pages using the Ionic selector. I attempted to use exports in my menu.module.ts file as shown below: @NgModule({ imports: [ CommonModule, Form ...

SignalR event handlers consistently return an undefined value for properties accessed within them

An angular application has been developed, utilizing signalR for notifications. The signalR package used is "@aspnet/signalr": "^1.0.4". Within the Angular App, a service has been created to manage all notifications received through signalR: private _hu ...

Solving automatically generated TypeScript MongoDB types for GraphQL results

Utilizing the typescript-mongodb plugin along with graphql-codegen to automatically generate Typescript types enables easy data retrieval from MongoDB and GraphQL output via Node. The initial input schema in GraphQL format appears as follows: type User @ ...

Creating an Angular reactive form with checkboxes and initializing a formArray with an existing array

I have a dynamic array of LkBoardTypeList fetched from a server. My goal is to push that array to form an array upon initialization, essentially displaying checkboxes based on the Board's name or ID in the array. I know how to push an empty array in r ...

Tips for resolving the React(TypeScript) issue "Invalid hook call."?

I received an error message stating: "Invalid hook call. Hooks can only be called inside of the body of a function component." within my React function: interface Items { items: any[] } const [items, setItems] = useState<Items>(); const ItemsList ...

Tips for effectively utilizing Mongoose models within Next.js

Currently, I am in the process of developing a Next.js application using TypeScript and MongoDB/Mongoose. Lately, I encountered an issue related to Mongoose models where they were attempting to overwrite the Model every time it was utilized. Here is the c ...

Building Custom Request Types for a Personalized Express Router in TypeScript (TS2769)

I've been facing challenges integrating custom Request types with TypeScript. Within my application, I have both public and private routes. The public routes utilize the Request type from Express. On the other hand, the private routes make use of a ...

JavaScript cannot determine the length of an array of objects

I'm encountering an issue with an array of objects named tagTagfilter. When I log it in the browser, it doesn't immediately show the correct length value inside. tagTagFilter: TagFilter = { filterName: 'Tag', tags: [] ...

Having trouble initializing useReducer in React paired with TypeScript

I'm currently delving into the world of TypeScript and facing a challenge with setting up the useReducer function. It seems like the solution might be a simple one, so apologies in advance. Below is an excerpt from my App.tsx file: import React, { use ...

What is the best way to implement a decorator for a class method variable within a NestJS framework?

import {isNotEmpty} from "class-validator"; export Service { create(createdto) { const {name,age} = createdto; @isNotEmpty() name //applying a decorator to ensure name is not null or undefined } } As the decorator is designed for ...

When the Mat menu radio button inside a Bootstrap popover is clicked, it will automatically close the popover

I have a popover from Bootstrap with the autoclose attribute set to "outside" in order to close the popover when clicked outside of it. The issue I'm facing is that inside the popover, there is a material menu that opens outside of the popover. The pr ...

Creating a generic groupBy function using Typescript

Questioning the TypeScript compiler's comprehension of my groupBy function, which includes an optional transformer for post-grouping data modification. Seeking suggestions on what steps to take next. const customGrouping = <A extends {}, C, B exten ...

Ways to resolve eslint typedef error when using angular reactive forms with form.value

I am facing an issue with my formGroup and how I initialized it. Whenever I try to retrieve the complete form value using form.value, I encounter an eslint error related to typecasting. userForm = new FormGroup<user>({ name: new FormControl<st ...

Error: Unable to inject null value into injector chain [c -> n -> J -> J -> J]

As I delve into an older angular project that was created by a former colleague, I am faced with the task of debugging it. However, as I run the application, I encounter the following error message: NullInjectorError: R3InjectorError(n)[c -> n -> J - ...