rxjs

Angular 2 : merge several http calls into one

人盡茶涼 提交于 2019-12-11 04:44:17
问题 I have a service that is used to upload pictures. To upload a picture, all I do is return this.http.post(/* ... */) And I get a subscription I can subscribe to in my component. But when I want to upload several pictures, I have to do for (let p of pics) { this.http.post(/* ... */); } My problem is that I would like to return the results of all calls instead of just one call. Is that possible ? EDIT Here is my service addPictures(files: File[], folder: string): Observable<Parse.Object[]> { let

Rxjs get distinct values of property value in array

谁说胖子不能爱 提交于 2019-12-11 04:44:11
问题 I am trying to get distinct values of a property in an observable array. let pt$ = Observable.of([{planTypeID : 1, description : 'test 1'}, {planTypeID : 2, description : 'test 2'}]); let planTypeIDs$ = pt$ .flatMap(a => a) .map(a => a.planTypeID).distinct().toArray(); Is this the right way to do it in rxjs, or is there a better way? 回答1: You could use .from instead of .of , that should spare you the .flatMap distinct will check the reference by default, so if you want to compare for contents

Binding to Input Properties of Child Component within Router Outlet

≯℡__Kan透↙ 提交于 2019-12-11 04:43:22
问题 I want to bind a parent component input element value to a child component property. The wrinkle is that the child component is nested within the parent via router-outlet. It seems like the best approach is to use a shared service between the parent and child component as demonstrated here. Here's my testing implementation: Parent component : import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { ThreadsService } from './threads.service'; @Component({

Observables in nestjs - Reading a file asynchronously

孤街浪徒 提交于 2019-12-11 04:40:51
问题 I am trying a use case of reading a json file asynchronously and sending it out as a response (as a rxjs observable data). Here is the service that I use import { logger } from './../../shared/utils/logger'; import { Injectable } from '@nestjs/common'; import * as fs from 'fs'; import * as path from 'path'; import { BehaviorSubject, Observable, pipe, of, from, throwError, merge} from 'rxjs'; import { map, filter, scan, take, debounce, switchMap, retry, catchError, mergeMap, delay, zip, tap,

Unable to translate text using ngx-translate's service-translate.get

我是研究僧i 提交于 2019-12-11 04:39:33
问题 I am able to translate text using translate pipe but currently struggling to load translations using translate service's get and instant method. Below is my code in app.component.ts export class AppComponent { event : string; constructor(private translate: TranslateService) { translate.addLangs(["en", "fr"]); translate.setDefaultLang('en'); let LangChangeEvent : {} let browserLang = translate.getBrowserLang(); translate.use(browserLang.match(/en|fr/) ? browserLang : 'en'); this.translate.get(

Angular 7 - How can I share the token renewal Observable?

六月ゝ 毕业季﹏ 提交于 2019-12-11 04:37:25
问题 Before each request a HTTP interceptor checks if the access token is expired and if so, it first renews the token and then continues the request. The problem is on pages that have multiple requests. On those pages the interceptor tries to renew the token for each request. How can I share the token renewal request in this case? The method that is responsible for token renewal is this: renewToken() { let refreshToken = // get refresh token let accessToken = // get access token if (!refreshToken

Unable to get property '0' of undefined or null reference

筅森魡賤 提交于 2019-12-11 04:27:12
问题 I am getting the following error which shows up in IE/Edge only. Unable to get propety '0' of undefined or null reference I am using RxJs observables in the following manner: getVersions(): void { this.databaseService.getProductVersions().subscribe( (versions) => this.processVersions(versions), (error) => console.error(error) ); } and in Chrome/Firefox this works without errors. productVersions looks like this: getProductVersions(): Observable<any[]> { let options = this.header(); let url:

wait for all pending request resolved and take value from last

江枫思渺然 提交于 2019-12-11 04:23:28
问题 I have a method getData() inside Angular app which calls on click every time when asc > desc sorting in the table is changed. If I click it 10 times in a row I will make 10 get request and data will assign to table every time when the request is resolved, so it makes it blinking till the last request. How can I waiting for data only for the last request and ignore another? this.getData() { this.endpointsService.getData(reqParams).pipe( takeUntil(this.ngUnsubscribe$) ).subscribe((data) => {

Notify from inner flatMap

谁说胖子不能爱 提交于 2019-12-11 04:22:55
问题 Here a quite complex sample: Main: this.runInstructionAndGetResult().subscribe({ next: val => console.log(`NEXT VALUE: ${val}`), error: val => console.log(`ERROR VALUE: ${val}`), complete: val => console.log(`COMPLETE`) }); Observables: public runInstructionAndGetResult(): Observable<string> { return this.runAnInstruction() .flatMap((data) => { console.info("flatMap of runAnInstruction:", data); return this.getInstructionExecutionStatusInPolling() .filter(data => data != "Polling") .take(1)

Angular2:Sharing data between components via routes -Subject

风流意气都作罢 提交于 2019-12-11 04:22:38
问题 Consider I have 3 components. 1. PatientComponent in /patient 2.PatientListComponent in /patient/list 3.PatientCareXComponent in /patient/care/x I used behaviorsubject in patient.service.ts to cast the data from patientlistcomponent. I face some issues: 1. Initially in /patient/list page from where data arrives, I see data visible in PatientComponent in console.logs but not PatientCareXComponent. 2. When i move to /patient page from /patient/list, the visible data also disappears. The code is