rxjs

How to subscribe array of Observable Forkjoin not working

耗尽温柔 提交于 2020-12-13 03:40:24
问题 I am trying to do multiple HTTP requests in angular using forkjoin.But when I subscribe to Observable it doest not give any response. let data = this.email.map((email) => this.get_student_service.get_student_by_email_id(email) ); forkJoin([data]).subscribe((res) => { console.log(res); }); console.log('Execute'); Here is my service get_student_by_email_id(email) { return this.fire_store .collection('User', (ref) => ref.where('email', '==', email)) .valueChanges(); } 回答1: Ok, if you're getting

Angular RXHJ map multiple object properties

邮差的信 提交于 2020-12-13 03:13:33
问题 My service returns object with events and count properties. Right now I need to do two requests. First to get events and second to get events count. I'd like to use Observables in component and async pipe in the template. I know how to achieve it subscribing to the service in the component, but I'd like to understand how to map both events and count to an observables with one request. What RxJs operator should I use ? import { Component, OnInit } from '@angular/core'; import { Event } from '.

Angular RXHJ map multiple object properties

岁酱吖の 提交于 2020-12-13 03:13:00
问题 My service returns object with events and count properties. Right now I need to do two requests. First to get events and second to get events count. I'd like to use Observables in component and async pipe in the template. I know how to achieve it subscribing to the service in the component, but I'd like to understand how to map both events and count to an observables with one request. What RxJs operator should I use ? import { Component, OnInit } from '@angular/core'; import { Event } from '.

Angular is it necessary to unsubscribe from this.activatedRoute subscriptions

天涯浪子 提交于 2020-12-12 17:13:30
问题 My code: ngOnInit() { this.activatedRoute.params.subscribe((params: Params) => { // do stuff }) this.activatedRoute.data.subscribe((data: any) => { // do stuff }) } My question is ... do I need to unsubscribe from these in ngOnDestroy? As a matter of habit I always unsub but not sure if it is necessary here. thanks 回答1: No, you don't need to unsubscribe from route observables From the Documentation When subscribing to an observable in a component, you almost always arrange to unsubscribe when

Angular is it necessary to unsubscribe from this.activatedRoute subscriptions

社会主义新天地 提交于 2020-12-12 17:08:44
问题 My code: ngOnInit() { this.activatedRoute.params.subscribe((params: Params) => { // do stuff }) this.activatedRoute.data.subscribe((data: any) => { // do stuff }) } My question is ... do I need to unsubscribe from these in ngOnDestroy? As a matter of habit I always unsub but not sure if it is necessary here. thanks 回答1: No, you don't need to unsubscribe from route observables From the Documentation When subscribing to an observable in a component, you almost always arrange to unsubscribe when

Angular is it necessary to unsubscribe from this.activatedRoute subscriptions

柔情痞子 提交于 2020-12-12 17:08:17
问题 My code: ngOnInit() { this.activatedRoute.params.subscribe((params: Params) => { // do stuff }) this.activatedRoute.data.subscribe((data: any) => { // do stuff }) } My question is ... do I need to unsubscribe from these in ngOnDestroy? As a matter of habit I always unsub but not sure if it is necessary here. thanks 回答1: No, you don't need to unsubscribe from route observables From the Documentation When subscribing to an observable in a component, you almost always arrange to unsubscribe when

BufferTime with leading option

帅比萌擦擦* 提交于 2020-12-12 12:29:48
问题 I have some events that I'd like to buffer but I'd like to buffer only after the first element. [------bufferTime------] Input over time: [1, 2, 3, -------------|---4, 5, 6 ----------------] Output over time: [1]-----------------[2,3]---[4]------------------[5,6] is there a way to do this? 回答1: I think this can be solved by dividing your stream into two, firstValue$ and afterFirstValue$, and then merging them. import { merge } from 'rxjs'; import { take, skip, bufferTime } from 'rxjs

Angular cross-service communication

谁说胖子不能爱 提交于 2020-12-06 07:06:26
问题 I have a statistics application. On the left side of my page I have list of themes, on the top - list of groups. The main part contains statistics items related to both theme and group. Also I have several services which provide business logic for my application. For simplicity let's talk about three of them: ThemeSerivce, GroupService and StatisticsService . End users could manipulate lists of themes and groups (add or remove items) and I have to recalculate statistics after each change. In

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

依然范特西╮ 提交于 2020-11-30 06:30:18
问题 Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This needs to happen for as long as the web app is open (so indefinitely). Currently, I'm using this: this.refreshDate = window.setInterval( () => this.store.dispatch(new FetchLastUpdate()) , 60000); And when view is destroyed/dismounted, I delete the

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

家住魔仙堡 提交于 2020-11-30 06:28:57
问题 Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This needs to happen for as long as the web app is open (so indefinitely). Currently, I'm using this: this.refreshDate = window.setInterval( () => this.store.dispatch(new FetchLastUpdate()) , 60000); And when view is destroyed/dismounted, I delete the