more()
函数应该从一个 get 请求中返回一个 Observable
export class Collection {
public more = (): Observable<Response> => {
if (this.hasMore()) {
return this.fetch();
} else {
// return empty observable
}
};
private fetch = (): Observable<Response> => {
return this.http.get("some-url").map((res) => {
return res.json();
});
};
}
在这种情况下,我只能在hasMore()
返回true时发出请求,否则在subscribe()
函数上会出现错误subscribe is not defined
。那么我该如何返回一个空的Observable呢?this.collection.more().subscribe(
(res) => {
console.log(res);
}, (err) => {
console.log(err);
}
);