I work in angular v7. Below is my backend response
[
{'type':'ex1','color':'red','extratype':'x'},
{'type':'ex1','color':'yellow','extratype':'x'},
{'type':'ex1','color':'blue',extratype:'f'},
{'type':'ex1','color':'orange',extratype:'f'},
{'type':'ex2','color':'gray','extratype':'r'},
{'type':'ex2','color':'pink','extratype':'r'},
{'type':'ex2','color':'purlple',extratype:'v'},
{'type':'ex2','color':'green',extratype:'v'},
]
I store this response in a html options like this:
This is the ts file
responsebackend;
results: any[] = [];
types: [] = [];
extratypes: [] = [];
ngOnInit(){
http.get(url)
.subscribe(res => this.responsebackend = res)
}
filter(){
this.results = this.filterCode(this.resposebackEnd);
}
filterCode(res){
let filtered: any[] = [];
res.forEach(val => {
filtered.push(val)
}
return filtered;
}
this.types = ['ex1','ex2'];
this.extratype = ['x','f','r','v'];
This is the ts code
<label for="types">TYPES</label>
<select name="types">
<option *ngFor="let t of types">{{t}}</option>
</select>
<label for="extratypes">extra TYPES</label>
<select name="types">
<option *ngFor="let ex of extratypes">{{ex}}</option>
</select>
<label for="results">RESULTS</label>
<select name="results">
<option *ngFor="let r of results.color">{{r}}</option>
</select>
if I select for example types ex1 and extratypes f I want to see inside the results options html tag I want to see only the colors of types ex1 and extratypes f