resolve: {course: ResolveService }
//这给了一个对象作为回报。而是得到一个可观察的。有可能吗?
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;
}
}
答案 0 :(得分:1)
在ResolveService
中修改resolve
以返回可观察的可观察量。 resolve函数将一直等到返回的observable发出,然后将其绑定到route config中定义的值。为了将一个observable发送到route组件,你需要将它包装在另一个observable中。像这样:
@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);
}
}