Aymen Kanzari
Aymen Kanzari

Reputation: 2013

Angular: You provided 'undefined' where a stream was expected

With the below resolve i get this error:

You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

the problem is the apifindExerciseFrameworkByEntityUsingGET return null.

@Injectable()
export class ExerciseFrameworkRouteResolver implements Resolve<any> {

    constructor(private apiExerciseFramework: APIExerciseFramework) { }

    resolve(route: ActivatedRouteSnapshot) {
        let array: (Observable<any[]> | Observable<any>)[] = [];
        return this.apiExerciseFramework.findExerciseFrameworkByEntityUsingGET({ externalId: route.paramMap.get('entityId') }).pipe(
            mergeMap((exerciseFramework: models.ExerciseFrameworkResponse) => {
                if (exerciseFramework) {
                    array.splice(0, 0, of(exerciseFramework));
                    array.splice(1, 0, this.apiRefService.findPriceZonesUsingGET());
                    array.splice(2, 0, this.apiRefService.findIndemnityAreaUsingGET());
                    return forkJoin(array);
                }
            })
        );
    }

}

Upvotes: 0

Views: 3350

Answers (1)

byte-this
byte-this

Reputation: 214

To solve this, you can add an 'else' condition after 'if (exerciseFramework)' to do something like 'return of(null)' so the return will still be an observable even if that service returns null. Then, the consumer can handle what to do if the output value is null.

Upvotes: 1

Related Questions