Can anyone assist me with sending http requests to service methods based on a dropdown selection using Rxjs Observables in Angular? I am passing the selected value from the dropdown to a child component. Thank you for your help.
child-component.ts
@Input() Type;
private data: any;
constructor(private apiService: ApiService){
switch(this.Type){
case 't1': this.apiService.getAllByT1(this.Type).subscribe(result => {
this.data = result;
});
break;
case 't2': this.apiService.getAllByT2(this.Type).subscribe(result => {
this.data = result;
});
break;
case 't3': this.apiService.getAllByT3(this.Type).subscribe(result => {
this.data = result;
})
}
ngOnInit(){
}
parent-component.html
<select [(ngModel)]="Type" class="form-control" (change)='onOptionsSelected($event)'>
<option id="1" value="t1">t1</option>
<option id="2" value="t2">t2</option>
<option id="3" value="t3">t3</option>
</select>
<app-child [Type]="Type" (getAPI)="onOptionsSelected($event)"></app-child>