Hi I am getting below responses from 2 api calls. First I'm calling 1st api and getting below respose
first response I'm getting from 1st api call
dataName = [
{
"id": "1",
"name": "stage1",
},
{
"id": "2",
"name": "stage2",
},
{
"id": "3",
"name": "stage3",
}
]
In dropdown i'm display name values
<mat-select (selectionChange)="onOptionsSelected($event)"required placeholder="Choose Data Name">
<mat-option *ngFor="let obj of dataName" >
{{obj.name}}
</mat-option>
</mat-select>
On selection of name from first dropdown I need to call a different api which will give me below response
cluName = [
{
"cname": "cname1",
"id": "3",
},
{
"cname": "cname3",
"id": "2",
},
{
"cname": "cname1",
"id": "2",
}
]
On dropdown selection when selecting name I need to send the ID instead of name to match the cname associated with the ID and display in another dropdown.
Suppose if I select stage2 then I need to send ID :2 and match in second response its associated cname(cname3,cname1) and display those cname in second dropdwon. How to achieve this please help.
On selectionChange I tried following method
onOptionsSelected(event) {
this.newArrayCluster = [];
this.cluName.forEach(element => {
this.newArrayCluster.push(element.find(item => item['id'] ===
event.value))});
console.log(this.newArrayCluster);
}
But I'm getting error "element.find is not a function".