Angular 使用 fork-join 的订阅方法不起作用
Angular subscription method with fork-join doesn't work
这是我的许可服务。我想要一个布尔数组。
import { forkJoin, Observable } from "rxjs";
import { map } from 'rxjs/operators';
private hasPermission(lessorId: number, userId: number, permission: string): boolean {
// returns boolean. It works correctly
}
hasPermissionsForX(permissions: string[]): Observable<boolean[]> {
return forkJoin([
this.userService.getUser(), //returns Observable
this.lessorService.getLessor() //returns Observable
]).pipe(
map(([user, lessor]) => permissions.map(permission => this.hasPermission(lessor.lessorId, user.userId, permission)))
)}
但是,我的订阅方法不起作用。该方法尚未进入函数。我什至得不到 console.log 回复。这是我的订阅方式。
const permissionsToCheck = ['firstPermission', 'secondPermission', 'thirdPermission'];
this.permissionService.hasPermissionsForX(permissionsToCheck).subscribe(([firstPermission, secondPermission, thirdPermission]) => {
console.log(firstPermission, secondPermission, thirdPermission)
})
我该怎么办?我做错了什么?
提前致谢!
这是我的许可服务。我想要一个布尔数组。
import { forkJoin, Observable } from "rxjs";
import { map } from 'rxjs/operators';
private hasPermission(lessorId: number, userId: number, permission: string): boolean {
// returns boolean. It works correctly
}
hasPermissionsForX(permissions: string[]): Observable<boolean[]> {
return forkJoin([
this.userService.getUser(), //returns Observable
this.lessorService.getLessor() //returns Observable
]).pipe(
map(([user, lessor]) => permissions.map(permission => this.hasPermission(lessor.lessorId, user.userId, permission)))
)}
但是,我的订阅方法不起作用。该方法尚未进入函数。我什至得不到 console.log 回复。这是我的订阅方式。
const permissionsToCheck = ['firstPermission', 'secondPermission', 'thirdPermission'];
this.permissionService.hasPermissionsForX(permissionsToCheck).subscribe(([firstPermission, secondPermission, thirdPermission]) => {
console.log(firstPermission, secondPermission, thirdPermission)
})
我该怎么办?我做错了什么?
提前致谢!