Reputation: 615
resolve: {course: ResolveService }
// This gives an object in return. Instead get an observable. Is it possible?
export const appRoutes: Routes = [
{ path: 'registration',
component: SomeComponent,
canDeactivate: [SomeGuardService],
resolve: {course: ResolveService } // This gives an object in retrun
},
// resolve
@Injectable()
export class ResolveService implements Resolve<Observable<any>> {
constructor(private dropDown: DropDownService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return this.dropDown.coursesDt;
}
}
Upvotes: 1
Views: 356
Reputation: 14239
In the ResolveService
modify the resolve
to return an observable of an observable. The resolve function will wait until the returned observable emits and then bind that to the value defined in the route config. In order to send an observable to the route component you will need to wrap it in another observable. Like so:
@Injectable()
export class ResolveService implements Resolve<Observable<any>> {
constructor(private dropDown: DropDownService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Observable<any>> {
return Observable.of(this.dropDown.coursesDt);
}
}
Upvotes: 1