Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rxjs 如何获得承诺_Rxjs_Rxjs5 - Fatal编程技术网

Rxjs 如何获得承诺

Rxjs 如何获得承诺,rxjs,rxjs5,Rxjs,Rxjs5,两者之间有区别吗 var source1 = Rx.Observable.of(42); const oneSubscription = source1.subscribe({ next: x => console.log(x) }); oneSubscription.unsubscribe(); 及 我认为要创造一个承诺,你必须先订阅它 但是在source2的情况下,它只是在没有订阅的情况下工作 可能有人可以解释。那是因为forEach内部也有订阅 /** * Subscr

两者之间有区别吗

var source1 = Rx.Observable.of(42);
const oneSubscription = source1.subscribe({
     next: x => console.log(x)
});
oneSubscription.unsubscribe();

我认为要创造一个承诺,你必须先订阅它

但是在
source2
的情况下,它只是在没有订阅的情况下工作


可能有人可以解释。

那是因为
forEach
内部也有订阅

/**
*  Subscribes an o to the observable sequence.
*  @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
*  @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
*  @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
*  @returns {Diposable} A disposable handling the subscriptions and unsubscriptions.
*/
forEach(observer: IObserver<T>): IDisposable;
/**
*给可观测序列标上一个o。
*@param{Mixed}[oOrOnNext]为可观察序列中的每个元素接收通知或调用操作的对象。
*@param{Function}[onError]在可观察序列异常终止时调用的操作。
*@param{Function}[onCompleted]在可观察序列优雅终止时调用的操作。
*@returns{Diposable}一个处理订阅和取消订阅的一次性文件。
*/
forEach(观察者:IObserver):IDisposable;

这是因为
forEach
也在内部订阅

/**
*  Subscribes an o to the observable sequence.
*  @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
*  @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
*  @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
*  @returns {Diposable} A disposable handling the subscriptions and unsubscriptions.
*/
forEach(observer: IObserver<T>): IDisposable;
/**
*给可观测序列标上一个o。
*@param{Mixed}[oOrOnNext]为可观察序列中的每个元素接收通知或调用操作的对象。
*@param{Function}[onError]在可观察序列异常终止时调用的操作。
*@param{Function}[onCompleted]在可观察序列优雅终止时调用的操作。
*@returns{Diposable}一个处理订阅和取消订阅的一次性文件。
*/
forEach(观察者:IObserver):IDisposable;

如何访问
next
error
forEach
中完成
?您可以添加更多功能,如
订阅
,请参阅@sreginogemoh此答案对您有帮助吗?您如何访问
next
error
forEach
中完成
?您可以添加更多功能,如在
订阅
,请参阅@sreginogemoh此答案对您有帮助吗?