【发布时间】:2018-07-19 12:48:13
【问题描述】:
Angular RxJS observables 新手,在时间和如何处理以下场景方面遇到问题。
我正在使用 RxJS:5.5.2 和 Angular 5.2.1
我有以下代码:
public checkRecType(myrec: string) {
this.myService.getRecType(myrec).subscribe(
result => {
if (result) {
this.recType = true;
} else {
this.recType = false;
}
});
}
public isRecord = (rc: any): boolean => {
this.checkRecType(rc);
return (_.find(this.record, {'name': rc}) && this.type);
}
我遇到的问题是,当我检查调用 checkRecType 的 isRecord 时,我上面订阅的 this.type 的值似乎没有及时返回以满足我的整个布尔返回。
如何在 Angular 5 中解决这个问题?我需要确保为上述处理返回一个布尔值,并且当 isRecord 返回其结果时this.type 可用。
【问题讨论】:
-
如果
getRecType是异步的,isRecord也需要是异步的,并且应该返回一个 observable。
标签: angular typescript rxjs observable