rxjs

Running histogram stream with Rx

元气小坏坏 提交于 2021-01-27 02:36:12
问题 I have the following single letter stream A B C A D B A C D And from this stream, I would like a stream of running count per letter (A,1) (A,1), (B,1) (A,1), (B,1), (C,1) (A,2), (B,1), (C,1) (A,2), (B,1), (C,1), (D,1) (A,2), (B,2), (C,1), (D,1) (A,3), (B,2), (C,1), (D,1) (A,3), (B,2), (C,2), (D,1) (A,3), (B,2), (C,2), (D,2) , i.e at each new letter, the totals are updated and emitted. I guess this problem is fairly language agnostic, so don't hesitate to propose a solution in your language of

Angular6 学习笔记——路由详解

北慕城南 提交于 2021-01-24 01:24:58
angular6.x系列的学习笔记记录,仍在不断完善中,学习地址: https://www.angular.cn/guide/template-syntax http://www.ngfans.net/topic/12/post/2 系列目录 (1) 组件详解之模板语法 (2) 组件详解之组件通讯 (3) 内容投影, ViewChild和ContentChild (4) 指令 (5) 路由 路由存在的意义 一般而言,浏览器具有下列导航模式: 在地址栏输入 URL,浏览器就会导航到相应的页面。 在页面中点击链接,浏览器就会导航到一个新页面。 点击浏览器的前进和后退按钮,浏览器就会在你的浏览历史中向前或向后导航。 那么,在angular中,是什么决定上述的行为呢? 对于一个新建的项目而言,只存在一个组件AppComponent,如果不增加其他的组件,意味着所有的行为就将在这一个组件里面完成,这种情况下,单一的组件将无法保存状态的变化,这显然满足不了上面的需求.所以,通常情况下,会如我在 组件通讯 中所写,组件之间呈如下的树形结构: 路由就是连接这些组件的筋络,它也是树形结构的.有了它,就可以在angular中实现上述的导航模式 可以把路由看成是一组规则,它决定了url的变化对应着哪一种状态,具体表现就是不同视图的切换 在angular中,路由是非常重要的组成部分, 组件的实例化与销毁

Angular 8 error: Http failure during parsing for http

 ̄綄美尐妖づ 提交于 2021-01-23 04:33:30
问题 I get an error when trying to call a service from Angular 8 app. Here is the service: const httpOptionsPlain = { headers: new HttpHeaders({ 'Accept': 'text/plain', 'Content-Type': 'text/plain' }) }; @Injectable() export class TripService { public getTripNameById(tripId: number): Observable<any> { return this.http.get<any>(`${this.baseUrl}/Trips/Trip/Name/${tripId}`, httpOptionsPlain); } And here is the Java rest api (works fine when calling from the browser): @GET @Path("Trip/Name/{fundId}")

Angular 8 error: Http failure during parsing for http

南笙酒味 提交于 2021-01-23 04:31:32
问题 I get an error when trying to call a service from Angular 8 app. Here is the service: const httpOptionsPlain = { headers: new HttpHeaders({ 'Accept': 'text/plain', 'Content-Type': 'text/plain' }) }; @Injectable() export class TripService { public getTripNameById(tripId: number): Observable<any> { return this.http.get<any>(`${this.baseUrl}/Trips/Trip/Name/${tripId}`, httpOptionsPlain); } And here is the Java rest api (works fine when calling from the browser): @GET @Path("Trip/Name/{fundId}")

Angular 8 error: Http failure during parsing for http

耗尽温柔 提交于 2021-01-23 04:30:52
问题 I get an error when trying to call a service from Angular 8 app. Here is the service: const httpOptionsPlain = { headers: new HttpHeaders({ 'Accept': 'text/plain', 'Content-Type': 'text/plain' }) }; @Injectable() export class TripService { public getTripNameById(tripId: number): Observable<any> { return this.http.get<any>(`${this.baseUrl}/Trips/Trip/Name/${tripId}`, httpOptionsPlain); } And here is the Java rest api (works fine when calling from the browser): @GET @Path("Trip/Name/{fundId}")

Angular 8 error: Http failure during parsing for http

巧了我就是萌 提交于 2021-01-23 04:26:43
问题 I get an error when trying to call a service from Angular 8 app. Here is the service: const httpOptionsPlain = { headers: new HttpHeaders({ 'Accept': 'text/plain', 'Content-Type': 'text/plain' }) }; @Injectable() export class TripService { public getTripNameById(tripId: number): Observable<any> { return this.http.get<any>(`${this.baseUrl}/Trips/Trip/Name/${tripId}`, httpOptionsPlain); } And here is the Java rest api (works fine when calling from the browser): @GET @Path("Trip/Name/{fundId}")

Rxjs conditional switchMap based on a condition

微笑、不失礼 提交于 2021-01-21 18:12:46
问题 I have a situation like the following: myObservable1.pipe( switchMap((result1: MyObservable1) => { if (condition) { return myObservable2; } else { return of(null); } }) ).subscribe(myObservable1 | myObservable2) => { So if condition is false I only have to perform one request, if the condition is true, I have to chain the first request to the following one, they are essentially two requests to the server api. Is there a better solution without returning that null ? Is there any conditional

Rxjs conditional switchMap based on a condition

喜欢而已 提交于 2021-01-21 18:12:22
问题 I have a situation like the following: myObservable1.pipe( switchMap((result1: MyObservable1) => { if (condition) { return myObservable2; } else { return of(null); } }) ).subscribe(myObservable1 | myObservable2) => { So if condition is false I only have to perform one request, if the condition is true, I have to chain the first request to the following one, they are essentially two requests to the server api. Is there a better solution without returning that null ? Is there any conditional

使用RxJs WebSocket,HighCharts和Angular实时数据

…衆ロ難τιáo~ 提交于 2021-01-21 14:04:12
Highcharts 是一款纯JavaScript编写的图表库,为你的Web网站、Web应用程序提供直观、交互式图表。当前支持折线、曲线、区域、区域曲线图、柱形图、条形图、饼图、散点图、角度测量图、区域排列图、区域曲线排列图、柱形排列图、极坐标图等几十种图表类型。 点击下载Highcharts最新试用版 在本教程中,我们将向您展示如何使用RxJs Websocket和官方的Highcharts Angular包装器可视化实时更新。您可以通过单击此GitHub链接访问整个项目。 备注 在本文中,使用随机数据来更新图表。没有服务器端代码的实现。 创建此项目有两个主要部分: 第一部分是设置Angular项目。为此,请遵循此Angular指南中的标准说明:设置本地环境和工作区。 第二部分是通过以下三个简单步骤来使用RxJsWebSocket和Highcharts设置Angular项目: 步骤1 由于我们将使用默认协议WSS(WebSocket协议),因此配置项目中的第一步是WebSocket import {webSocket}从rxjs/webSocket包中导入。 顺便说一句,如果你不熟悉WSS,这里是当有订阅的插座会发生什么的简短说明: 该rxjs管是用于撰写运营商的方法。订阅时收到的Emitted值仅被推入数组中并分配给data属性

How do I map http request response to my defined object in TypeScript

六月ゝ 毕业季﹏ 提交于 2021-01-21 05:21:21
问题 I'm getting to know Angular, TypeScript and RxJS. I have an http request that returns a JSON. In this JSON there is data that I need to construct my defined object. Let's say, that my object is this: export class RegularUser { constructor( public id: number, public firstName: string, public lastName: string, public token: string ) {} } Now, I am sending a request to some API, which returns data in this format: { success: boolean, uid: number, first_name: string, last_name: string, cid: number