observable

Angular5 http reponse interceptor unable to read status code

早过忘川 提交于 2019-12-23 03:01:24
问题 I am trying to intercept http responses and redirect any 401's but the err object below is only returning me the following string. I was expecting to at least find the status code.. 401 - Unauthorized Details: Http failure response for http://localhost:4200/api/foo: 401 Unauthorized I can see in the network tab that a well formed 401 is being returned by the server. Any ideas on how I can read them correctly? intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>

Leaking this in constructor

て烟熏妆下的殇ゞ 提交于 2019-12-23 02:54:36
问题 The Controller class is a singleton, which seems to be a special case allowing for safely passing this to Controller . Netbeans gives Configure "passing suspicious parameters in the constructor" hint for controller.addObserver(this); which makes me ask what the better technique would be, although I gather it's not a good approach. package net.bounceme.dur.usenet.swing; import java.util.Observable; import java.util.Observer; import java.util.logging.Logger; import javax.mail.Folder; import

Angular service not working with http.get observable

霸气de小男生 提交于 2019-12-22 18:59:08
问题 I am trying to retrieve json file from the server using http.get and subscribe to the observable from a component. However, it's returning an error, not the data. Can you please tell me where I'm going wrong: import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import { Observable } from 'rxjs'; @Injectable() export class MoviesService { constructor(private http: Http) { } getMovies() : Observable<any> { let url = API_URL; return this.http.get(url); } } and here's

How create observable with parameters in Angular 6?

让人想犯罪 __ 提交于 2019-12-22 13:13:31
问题 I want to create an observale which can pass some parameters in Angular 6. Below is the sample code for creating observable in Angular site https://angular.io/guide/observables, but it doesn't explain how to pass any parameters. // Create an Observable that will start listening to geolocation updates // when a consumer subscribes. const locations = new Observable((observer) => { // Get the next and error callbacks. These will be passed in when // the consumer subscribes. const {next, error} =

How create observable with parameters in Angular 6?

只谈情不闲聊 提交于 2019-12-22 13:13:07
问题 I want to create an observale which can pass some parameters in Angular 6. Below is the sample code for creating observable in Angular site https://angular.io/guide/observables, but it doesn't explain how to pass any parameters. // Create an Observable that will start listening to geolocation updates // when a consumer subscribes. const locations = new Observable((observer) => { // Get the next and error callbacks. These will be passed in when // the consumer subscribes. const {next, error} =

Angular 2 / RXJS - need some help batching requests

百般思念 提交于 2019-12-22 12:28:48
问题 I keep reading rxjs documentation but getting lost in all the operators.. this is what i got so far let obs = Observable.from([1, 3, 5]) so what i need this to do is take() some set amount from the array. use the results in a post request, when that comes out successful then i need to restart the process. I want to collect all the results, and keep progress as the process is going (for a progress bar) I don't need the code for all of that. what i really need to know is how to use rxjs to

Angular service that returns observables/subjects from a cache array to multiple instances of a component in realtime

前提是你 提交于 2019-12-22 11:32:05
问题 USE CASE I have a content page that has multiple instances of UserActionsComponent. I also have a global DataService that acts as a data provider with (wannabe) advanced caching. Data fetch hierarchy: In-Memory Cache >> Browser Storage (async) >> HTTP Request UserActionsComponent Requests dataService.getData(URL,params,method) PS: params has details like blogId which makes the hash signature unique DataService (.getData()) 1) Makes a unique hash KEY using something like genUniqueHash(URL

Conditional emission delays with rxjs

删除回忆录丶 提交于 2019-12-22 09:56:37
问题 From picture to code? How to get the Out observable from Data and Gates? Data is an observable of any kind e.g. JSON objects to be sent to a remote backend Gates is a boolean observable, where the ticks correspond to true and the crosses to false. For example, Internet connectivity whereby true means the network became accessible and false reflects a disconnection. Out is the resulting observable, which emits the same as Data, sometimes immediately, sometimes with a delay, depending on the

Accessing async variable of service

蹲街弑〆低调 提交于 2019-12-22 09:18:03
问题 This is part of my first Angular 4 project. I am currently able to call the searchCall function just fine from a search bar, but the data being stored in tweetsData doesn't seem to be in scope with my *ngFor call in app.component.html, as well as being an asynchronous backend call to the twitter api. I get this error: TypeError: Cannot read property 'subscribe' of undefined, so I must not have the observable setup correctly. Any help is greatly appreciated. twitter.service.ts import {

What is the difference between throttleTime vs debounceTime in rxjs and when to choose which?

会有一股神秘感。 提交于 2019-12-22 08:51:35
问题 I'm trying to understand throttleTime vs debounceTime and which one is to be used when? I have an upvote button that makes an API request to the backend (which counts the votes). User can submit button multiple times, but I'd like to limit the times per second button can be pressed. I know throttleTime and debounceTime operators can do that, but which should I choose better? const upvoteClicks = fromEvent(this.el.nativeElement, 'click') .pipe(debounceTime(500)) .subscribe(() => this.myService