gpt4 book ai didi

javascript - 如何在 Angular 6 中使用新的 RXJS 6 管道/映射返回解析数据?

转载 作者:行者123 更新时间:2023-11-29 17:43:55 24 4
gpt4 key购买 nike

<分区>

如何在 Angular 6 中使用新的 RXJS 6 管道/映射返回已解析的数据?

@Injectable()
export class RecentDataResolver implements Resolve<RecentData> {
constructor(
public data: DataService,
private api: ApiService) {}

resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<any> {

this.api.get('/data/recent').pipe(map(response => {
return response as RecentData;
}));
}
}

当我在组件中订阅它时解析的数据是null:

constructor(private route: ActivatedRoute, public data: DataService) {

this.route.data.subscribe(routeData => {
this.recent = routeData.recent;
console.log('data', routeData.recent);
});

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com