observable

How to handle/queue multiple same http requests with RxJs?

点点圈 提交于 2020-01-01 06:00:13
问题 I am making an Angular 4 app. Components are subscribing Observable. Sometimes Observable call the same url. For example 'refresh Access Token' if needed before any http request. But if I make different 3 http requests, it will "refresh if needed" 3 times the refresh token. So how to make only one http get to get a refreshed access token, and make the other observables 'wait' for the first one ? (I know 'wait' is not the good word for Observables). public get(url: string, options?:

How to return value inside subscribe Angular 4

给你一囗甜甜゛ 提交于 2020-01-01 04:04:28
问题 I'm new to observables in angular. I have a problem wanting to return a value inside a subscribe method. I have the following method ( getFirebaseData(idForm:string):observable <any[]> ): getTotalQuestions(idForm:string){ let totalQuestions:number; this.getFirebaseData(idForm+"/Metadatos") .subscribe(items => { items.map(item => { totalQuestions=item.Total; console.log(totalQuestions); }); } ); console.log(totalQuestions); return totalQuestions; } the firts console.log(totalQuestions) print 4

Angular 2 Updating objects in “real time.”

若如初见. 提交于 2020-01-01 03:33:05
问题 Hi I’m trying to wrap on how to update a table angular 2. Here is what I have: Backend: express / MongoDB. Updates are feed into the DB via an external app Data: 90% data will will be static. 10% of the data updates every second. I’ve looked at Observables / promises. HTTP requests/ socket IO but can’t wrap my mind around the concepts. Main Question: can I use observables with socket.io to update records? Other Questions about data updates Angular 2’s Observables – are observables use only

Angular2 Observable - how to wait for all function calls in a loop to end before proceeding?

人走茶凉 提交于 2019-12-31 17:49:33
问题 I am trying to improve my knowledge of Angular2 by migrating an application currently written in Angular1 One feature in particular has me stumped. I am trying to replicate a feature where a calling function waits to proceed until the function it is calling has completed a loop of promises. In angular one the function I am calling looks basically like this: this.processStuff = function( inputarray, parentnodeid ) { var promises = []; var _self = this; angular.forEach( inputarray , function(

Using Observable in Android

放肆的年华 提交于 2019-12-31 10:02:52
问题 I want to implement a Navigation View with many fragments that depend totally on a value defined in the MainActivity . I know that variables in MainActivity can be accessed using method defined in MainActivity from other Fragments to get the value , but the catch here is that the value of the variable in MainActivity may change (which runs on an AsyncThread ). Now, I either change the code such that my Fragments update their value based on some event in the fragment itself or use

Problem with retrieving headers in angular 6?

别等时光非礼了梦想. 提交于 2019-12-31 03:58:06
问题 Here is my service executeProcess(): Observable<any> { return this._httpClient.post(this.baseUrl + '/api/survey/process/execute', {}, { observe: 'response', responseType: 'text' as 'text' }); } And in my component I am calling it like this this._httpService.executeProcess().subscribe(res => { console.log(res); } And this is my res.headers { "normalizedNames": {}, "lazyUpdate": null, "headers": {} } which has a headers object which is empty. In the backend of this api, I am sending a header

HttpClient Subscribed Response Headers Undefined

只愿长相守 提交于 2019-12-31 03:35:06
问题 can anyone give me any reasons on why I'm not getting any headers when getting a response back from http.post? this.http.post<Response>(url, body).subscribe((res: Response) => console.log(res.headers)); res.headers logs 'undefined', however in Chrome DevTools, the response is showing the headers I'm looking for. Side note: I do have Access-Control-Expose-Headers set to the header I'm wanting to expose. Any idea why this would be? 回答1: To observe a response instead of a typecasted body, which

Angular2 HTTP using observables subscribe showing data undefined

喜夏-厌秋 提交于 2019-12-30 06:53:42
问题 I don't know what I'm doing wrong but somehow i'm not able to read data, though the data is coming from server in response and even the data is getting showed inside service extractData method when I'm putting the console but in component inside subscribe function it is giving me undefined. Help me what I'm doing wrong, what I'm assuming is that this is the problem of async but, I have no idea how correct it. Any help will be appreciable. Thanx in advance Component.ts import { Component,

Property 'subscribe' does not exist on type '() => Observable<any>'

两盒软妹~` 提交于 2019-12-30 01:51:11
问题 service file import { Observable } from 'rxjs/Rx'; import { Http,Response} from '@angular/http'; import { Injectable } from '@angular/core'; import 'rxjs/add/operator/Map'; @Injectable() export class VideoService { private geturl = '/api/videos'; constructor(private _http:Http) { } getvideos() { return this._http.get(this.geturl).map((response:Response) => { response.json() }); } } here is where the subscribe method showing this error import { VideoService } from '../video.service'; import {

Angular 2 Using Observable.debounce() with Http.get

可紊 提交于 2019-12-29 08:41:16
问题 I understand that Observable.debounce() can be used to process rapid fire form input. As Http GET also returns an Observable, I wonder it it is possible to debounce rapid http requests? I tried debounceTime() but it did not appear to do anything. public getStuff(p1, area:string, p2:string): Observable<number> { return this.http.get(some_url) .map(r => r.json()) .debounceTime(10000) .catch(this.handleError); }; 回答1: The debounceTime allows to buffer events and only handle the last one after an