[英]What does Observable.from([true]) do?
Looking through my code base, I've noticed that a previous developer, when creating a function to transform one model to another, commonly uses the following code: 通过我的代码库,我发现以前的开发人员在创建将一个模型转换为另一个模型的函数时,通常使用以下代码:
property: Observable.from([true]);
What does this accomplish exactly and why can't the value just be set to true
? 这究竟能完成什么工作,为什么不能将值仅设置为
true
?
According to the documentation , the from
operator: 根据文档 ,
from
运算符:
Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object.
从数组,类似数组的对象,Promise,可迭代对象或类似Observable的对象创建一个Observable。
Why should we use the from
operator if the array is only ever 1 value? 如果数组只有1个值,为什么还要使用
from
运算符?
I am guessing, these are conventions followed by some teams or individuals, where 我猜这是一些团队或个人遵循的惯例,
property
is of type Observable<boolean>
, which means this member data is calculated asynchronously (and is most likely to be used with an async
pipe in the HTML incase of angular). property
的类型为Observable<boolean>
,这意味着该成员数据是异步计算的(在有角度的情况下很可能与HTML中的async
管道一起使用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.