How to make dependent another dropdown for filter in angular
To build a cascading dropdown, we have to take two dropdown.
Add the following code in html file.
The second dropdown option will be fetched dynamically. So, here we will use the concept of (ngFor) loop which can be used to populate an html template based on the condition.
Suppose, if there are 3 state then option will be repeated 3 times and will be stored into select element.
We need to define the array (states) in our ts file. It will take count of the state and on based on the count it push the value in the state and it will repeat n number of times.
On every value change in the option, the value will be stored in two way binding [(ngModel)] and the change function will be triggered. We declare the function in ts file.
Now, place the following code in ts file.
The output for this will be :
No comments:
Post a Comment