Skip to content
Advertisement

how to display cities in one dropdown based on selected state in other dropdown using json data in angular ionic?

following are my files for html, .ts and json . As json data was very extensive therefore i have just added a few states and their cities. my 1st dropdown is showing all states. Now I want to match my 1st dropdown’s selected value of state with a key “state” in “cities” object in my json file so i can populate 2nd dropdown with cities relevant to that state. and I want to do this in function “getCitiesForSelectedState”. please help me find solution for this.

//.ts file

JavaScript

//html file

JavaScript

//json file

JavaScript

Advertisement

Answer

You can do it with the $event parameter. Make sure to compare your values safely.

If your value is not in the right type or has spaces or unwanted chars, this c.state == val might not work.

You can use the trim function to compare your value safely: c.state.trim() == val.trim()

HTML

JavaScript

TS

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