函数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()
是真的,否则我得到一个错误的subscribe()
函数subscribe is not defined
,我怎么能返回一个空的可观察对象?
this.collection.more().subscribe(
(res) => {
console.log(res);
}, (err) => {
console.log(err);
}
);