【发布时间】:2017-05-04 19:23:41
【问题描述】:
我想调用一个返回 promise 的函数,然后将结果传递给另一个返回 observable 的函数。我需要按顺序执行此操作并将最终结果作为可观察的,以便我可以订阅。
例如:
// Call a function and return a Promise
myPromise() {}
// Make an http call and return an Observable
myObservable() {}
// Call myPromise() then call myObservable() and return
// an Observable with the result
// *I don't know how this function should be*
myFunction() {}
// Subscription
myFunction().subscribe(
result => console.log(result),
error => console.log(error),
() => console.log('completed'));
我该怎么做?
【问题讨论】:
-
你有什么问题?也许我误解了你的问题,这似乎很简单。
promiseReturningFunction().then(observableReturningFunction).subscribe(observer)和在调用promiseReturningFunction之前,请确保它是第一次调用。我在这里错过了什么? -
您有任何代码示例以便我们为您提供帮助吗?
-
不需要调用一次,算了。我用一个小示例代码编辑了这个问题。
标签: javascript http promise rxjs observable