是的,而且记录在案的是更一般的RXJS问题。无论如何,你必须将承诺转换为可观察的,然后像这样链接调用:
import { of, from, Observable } from 'rxjs';
import { map, filter, flatMap } from 'rxjs/operators';
class Caller {
public constructor(){}
public call() : Observable<Item[]> {
//the promise returned from your method it has to be typed with boolean
var permission = new Promise<boolean>(function(resolve, reject) {
setTimeout(function() {
resolve(true);
}, 300);
});
//calling from(prommisse) converts promes to observable.\
return from(permission)
.pipe(
filter(t => t), //just a trick to avoid if statemt in the flatMap call
flatMap( t => {
//call your http get method here
var it:Item = {property: "1"};
return of<Item[]>([it])
}))
}
}
export class Item {
property: String
}