Angular 角度6:无法从路由解析程序获取数据

Angular 角度6:无法从路由解析程序获取数据,angular,angular6,angular-router-guards,Angular,Angular6,Angular Router Guards,我有一个路由配置,允许用户根据如下标准查看最近完成的活动: { path: 'workspace', component: WorkspaceComponent, children: [ { path: 'upload', component: UploadComponent }, { path: 'verify', component: VerifyComponent, resolve:{dataObject: RecentActivityResolver}}]} ngOnInit(){

我有一个路由配置,允许用户根据如下标准查看最近完成的活动:

{ path: 'workspace', component: WorkspaceComponent, children: [
{ path: 'upload', component: UploadComponent },
{ path: 'verify', component: VerifyComponent, resolve:{dataObject: RecentActivityResolver}}]}
ngOnInit(){
    this.activatedRoute.data.subscribe((data: Data) => {
        console.log(data['dataObject']); // undefined
        this.displayActivity = data['dataObject'];
    });
    this.activatedRoute.queryParams.subscribe((data: Data) =>{
        console.log(data['id']); // correct data here
    });
}
解析器从存储在服务类中的arraylist返回一个对象。我没有直接访问VerifyComponent中的服务类,因为我打算很快从阵列更改为HTTP请求

@Injectable()
export class RecentActivityResolver implements Resolve<RecentActivityModel>{
constructor(private recentActivity: RecentActivityService){}
resolve(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RecentActivityModel> |
Promise<RecentActivityModel> | RecentActivityModel {
    console.log(activatedRoute.queryParams['id']); // gives me the correct result here
    return this.recentActivity.recentActivities[+activatedRoute.queryParams['id']];
    }
}

我无法理解为什么数据没有出现在这里。有人能指引我吗?提前感谢。

奇怪的是,解决方案/解决方法是将解析器移动到父级。但我真的想知道这是为什么

{ path: 'workspace', component: WorkspaceComponent, resolve:{dataObject: RecentActivityResolver}, children: [
{ path: 'upload', component: UploadComponent },
{ path: 'verify', component: VerifyComponent }
]}

我以前没见过这个。。。解析:{dataObject:RecentActivityResolver}。。。试试这个。。。解决方案:RecentActivityResolver。。。并使dataObject成为JSON解析响应的一部分——值得使用“RxJs of”来模拟可观察的响应,这样就可以很容易地替换为HTTPlater@danday74他使用的模式与@danday74中显示的模式相同。我尝试添加一个简单的字符串解析器,效果非常好。我用给出的解决方案解决问题,但我不理解这种行为。谢谢你的帮助!