Skip to content
Advertisement

Change in one dropdown value is affecting other dropdowns

I have a add button which will keep on adding a div container which consists of two dropdowns. On selecting on dropdown we are setting other dropdown data.

When I click on add div it will add a second div with both dropdowns. But, change in one dropdown is affecting other dropdown.

app.component.ts

JavaScript

app.component.html

JavaScript

After adding div, each dropdown should have respective selected values.

Advertisement

Answer

So, when I click on add div it will add a second div with both dropdowns. But, change in one dropdown is affecting other dropdown.

That’s because these two dropdowns share the same variable/storage. You need to give them separate storage. In this case, we create a list of object with selectedCountry and selectedCity.

app.component.ts

JavaScript

app.component.html

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement