I'm currently working on a function that makes an API call and receives an array of objects as the response. My goal is to map this response to an observable of type Business, but I'm unsure about the correct mapping process within the getBusiness function.
Here is a sample response:
[
{
Id: 2,
Name: "Joe"
}
]
export interface Business {
id: string;
name: string;
}
getBusiness(): Observable<Business[]> {
const url = "";
return this.http.get(url, this.httpOptions)
.pipe(
map((data: Business[]) => data as Business[] )
)
}
@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss'],
})
export class Component implements OnInit {
this.apiService.getBusiness() {
.subscribe((res: Business[]) => console.log(res))
}