0

I'm working on a solution where I have a table grid that allow users to add and remove items from the table. Inside of each row are select columns that represent states, cities and mlb teams. I'm trying to do a cascading select list so when the user select a state, then a list of cities appear for the user to choose from and then when they select a city, then a list of MLB teams appears to choose from.

I can't figure out how to get the selected state value and then how to properly populate the city select list for the current row I'm on.

Help is needed.

onStateChange(index: number) {
    const stateID = Number(this.mlbForm.get('items')?.get('state')?.value);

    //
  }

Its on this call is where the stateID returns 'NaN'. Provided below is a link to my sample application on StackBlitz https://stackblitz.com/edit/stackblitz-starters-vkpoxs?file=src%2Fapp%2Fapp.component.ts

Any help I would gladly appreciate it.

5
  • this.items.at(index)?.get('state')?.value; Commented Nov 24, 2024 at 20:09
  • You have a formarray inside the formgroup. Commented Nov 24, 2024 at 20:10
  • stackblitz.com/edit/… Commented Nov 24, 2024 at 20:10
  • 1
    Hi @StefaniToto, would be great to write it as answer post. So that this would help for those who have the similar problem. Thanks. Commented Nov 25, 2024 at 3:06
  • I'd vote to have the relevant code in the question also. As without following the link, SO users have no way to understand the problem. Commented Nov 25, 2024 at 8:15

1 Answer 1

0

You should use the at() to get the array inside the group.

this.items.at(index)?.get('state')?.value

Fix below: https://stackblitz.com/edit/stackblitz-starters-teeuxb?file=src%2Fapp%2Fapp.component.ts&file=src%2Fapp%2Fapp.component.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.