karansys
karansys

Reputation: 2719

Angular: want to update dropdown list based on value chosen in another drop down

I select daemon value (place, name or thing) and each of this daemon have dedicated productlist ( once again a drop down). I have replicated this in stackblitz here stackblitz of code what I tried.

What I am not able to do is update the second dropdown based on the value of daemon selected.

Upvotes: 0

Views: 857

Answers (1)

Aravind
Aravind

Reputation: 41543

Modify your selectDaemon function as below

selectDaemon(value){
   console.log("daemon selected"+value);
   this.globalValueDaemon = value;
   let selectedProductList = this.stateGroups.find(item=>item.daemon==value).productlist;
   this.productGroupOptions=of(selectedProductList)
}

Add the import for the of operator as

import {Observable,of} from 'rxjs';

and remove the assignment to this.productGroupOptions from ngOnInit()

Updated Stackblitz

Upvotes: 2

Related Questions