1

I am getting an error on IProject
must return a value.

I want to return the result from the api.

public getProjectDetails(projectId: number): IProject {
        this.testStationService.getProjectById(projectId)
            .subscribe(
                (res) => {
                    return res;
                });
    }
Ferdipux
  • 5,116
  • 1
  • 19
  • 33
jitenderd
  • 181
  • 3
  • 15

2 Answers2

0

You have to return your service method as well

return this.testStationService.getProjectById(projectId)

bugs
  • 14,631
  • 5
  • 48
  • 52
0

You are trying to return a value of an asynchronous Observable, synchronously. So by the time getProjectById emits a value, the function getProjectDetails has already finished and return nothing.

You have to return the Observable itself and subscribe to it where you need its values, or even better use the async-pipe -> https://angular.io/api/common/AsyncPipe

So getProjectDetails would look like this:

public getProjectDetails(projectId: number): Observable<IProject> {
    return this.testStationService.getProjectById(projectId);
}
Leon
  • 480
  • 4
  • 8