我正在使用RXJS 6.5.4
在打字稿服务中,我有:
=MID(A1,B1+1,FIND(")",A1,B1)-B1-1)
第二种方法,我需要验证会话是否已通过身份验证,然后请求当前用户并将其转换为另一个Observable,以解决当前用户是否为管理员。
我正在尝试,但是出现错误:
=MID(A1,MIN(FIND({"(1","(2","(3","(4","(5","(6","(7","(8","(9","(0"},A1 & "(1(2(3(4(5(6(7(8(9(0"))+1,FIND(")",A1,MIN(FIND({"(1","(2","(3","(4","(5","(6","(7","(8","(9","(0"},A1 & "(1(2(3(4(5(6(7(8(9(0")))-MIN(FIND({"(1","(2","(3","(4","(5","(6","(7","(8","(9","(0"},A1 & "(1(2(3(4(5(6(7(8(9(0"))-1)
这是编译错误:
isAuthenticated(): Observable<boolean> {
// request
}
currentUserPromise(): Promise<User> {
// request the User model and return via Promise.
}
答案 0 :(得分:2)
如果您需要订阅一个内部可观察的对象,则需要一个高阶运算符,例如switchMap
,map
用于同步数据转换。 mapTo
是一个运算符,不能像您使用它时那样使用,请使用of
将值转换为可观察的值...您还需要返回它才能订阅。 / p>
isAdmin(): Observable<boolean> {
return this.isAuthenticated().pipe(switchMap(authenticated => {
if (authenticated) {
return from(this.currentUserPromise().then(user => user.roles.indexOf('ADMIN') > -1))
}
return of(false); // there is no authentication, so no current user and no admin!
}));
}