我正在轮询一个RESTful端点来刷新我的在线聊天消息.我知道一个实时聊天的最佳方法是Websockets,我只是想了解RxJS如何与Angular 2一起工作.
return Rx.Observable .interval(1000) .flatMapLatest(() => this.http.get(`${AppSettings.API_ENDPOINT}/messages`)) .map(response => response.json()) .map((messages: Object[]) => { return messages.map(message => this.parseData(message)); });
但是我的Typescript transpiler返回此错误:
Property ‘flatMapLatest’ does not exist on type ‘Observable<number>’
我使用的是RxJS 5.0.0-beta.0
如果我使用merge而不是flatMapLatest,它根本不调用API.
您需要使用switchMap(),RxJS 5中没有flatMapLatest().
请参阅Migrating from RxJS 4 to 5 …虽然docs不是很清楚switchMap()…
Returns a new Observable by applying a function that you supply to each item emitted by the source Observable that returns an Observable,and then emitting the items emitted by the most recently emitted of these Observables.
原文地址:https://www.jb51.cc/angularjs/140726.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。