我正在尝试实现一个返回布尔值可观察值的方法,如果另一个可观察值包含真实值,则该值为true。这是大多数实现:
/**
* Observe changes to the values.
*
* @param key
* @return An {@link Observable<boolean>} indicating whether the value exists.
*/
public exists(key:string) {
if (!this.subjects[key]) {
throw new Error(`No subject exists for the key ${key}`);
}
return this.subjects[key].asObservable().pipe(???);
}
是否存在执行value != null
检查的操作员?像isDefined
运算符一样?
答案 0 :(得分:1)
map(value => !!value)
没有运算符可以将某些值转换为布尔值。