我需要从 Angular 8 的两个 api 返回数据。
我创建了这个解析器:
export class AccessLevelResolve implements Resolve<any>{
constructor(private accessLevel: AccessLevelService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
let id = +route.paramMap.get('id');
const getControllerList = this.accessLevel.getAll().pipe(
map(
res => {
if (res) {
return res.date;
}
}
)
)
const getRoleAccessRole = this.accessLevel.getAllWithId(id).pipe(
map(
res => {
if (res) {
return res.date;
}
}
)
)
return forkJoin(getControllerList, getRoleAccessRole).subscribe(res => {
return {
controllerList: res[0],
accessRoleList: res[1]
}
}
)
}
但它向我显示了这个错误:
Type 'Subscription' is missing the following properties from type 'Observable': _isScalar, source, operator, lift, and 6 more.
有什么问题吗???我该如何解决这个问题?
最佳答案
您不在解析器中订阅,您返回可观察和 Angular 订阅:
return forkJoin(getControllerList, getRoleAccessRole).pipe(map(res => {
return {
controllerList: res[0],
accessRoleList: res[1]
}
}))
关于javascript - 类型 'Subscription' 缺少类型 'Observable<any>' : _isScalar, 源、运算符(operator)、提升和其他 6 个属性的以下属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59118814/