Within my service, I have a function that returns an Observable. This function takes data from another service, applies transformations to it, and then returns it as an Observable.
@Injectable({
providedIn: 'root'
})
export class ReportColumnHeaderService {
constructor(private companyService: CompanyService) {}
public getColumnHeaderElements(variableDimensions: string[]): Observable<HeaderElement[]> {
return Observable.create(function(observer) {
this.companyService.getCompanies( (companies: Company[]) => {
let headerElements = getHeaderElements(companies);
observer.next(headerElements);
observer.complete();
});
});
}
}
A challenge faced is that this.companyService
is undefined within the function
. To address this issue, I attempted using an arrow function like so:
return Observable.create((observer) => {
this.companyService.getCompanies( (companies: Company[]) => {
let headerElements = let headerElements = getHeaderElements(companies);
observer.next(headerElements);
observer.complete();
});
});
However, this code does not compile and displays an error message stating Expected 0 arguments, but got 1.
Any suggestions on how to resolve this issue would be greatly appreciated.