【问题标题】:Type 'Subscription' is missing the following properties from type 'Observable<any>': _isScalar, source, operator, lift, and 6 more类型 'Subscription' 缺少来自类型 'Observable<any>' 的以下属性:_isScalar、source、operator、lift 和另外 6 个
【发布时间】:2020-03-25 21:05:59
【问题描述】:

我需要从 angular 8 中的 tow 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]
        }
    }
    )

}

但它告诉我这个错误:

“订阅”类型缺少“可观察”类型中的以下属性:_isScalar、源、运算符、提升等 6 个。

有什么问题???我该如何解决这个问题??

【问题讨论】:

    标签: javascript angular typescript


    【解决方案1】:

    你没有在你的解析器中订阅,你返回 observable 和 angular 订阅:

    return forkJoin(getControllerList, getRoleAccessRole).pipe(map(res => {
        return {
            controllerList: res[0],
            accessRoleList: res[1]
        }
    }))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      相关资源
      最近更新 更多