I encountered an issue in my IDE while trying to run the following code.
Within my component, I am making a call to a service in the ngOnInit method to fetch some data. This service, in turn, calls another service to gather additional information before finally returning the desired data.
Here is the code snippet from the component:
ngOnInit() {
const token = "abc";
this.service.getContactPersons(token).subscribe(
persons => this.contactPersons = persons
);
}
And here is the relevant part of the service code:
getContactPersons(token: string): Observable<ContactPerson[]> {
return this.tokenService.getParameters(token).pipe(
switchMap((data: Params) => {
return this.http.get<Properties>(
this.baseUrl + `/abc/${data.param1}/properties/${data.param2}`
);
})
).subscribe((data: Properties) => data.contactPersons);
}
However, when running the code, I received the error message: "Type 'Subscription' is missing the following properties from type 'Observable': _isScalar, source, operator, lift, and 6 more."