rxjs

Angular2. Map http response to concrete object instance

心不动则不痛 提交于 2020-01-02 04:46:07
问题 Сommon approach to process http response is like that: return this._http.get(url) .map((res: Response) => res.json()); which provides you with an Observable<Object[]> where Object is dynamically created type from json de-serialization. Then you can use this result in *ngFor="let item of result | async" etc... I'd like to get a specific type instance (meaning using new operator to call the type's constructor). Tried different ways to achieve something like that: .map((res: Response) => { let

Angular2 + ngrx/store for handling failure HTTP requests

℡╲_俬逩灬. 提交于 2020-01-02 02:23:07
问题 I want to have a simple code path for creating and dispatching HTTP actions. What I would like to do is something like: this.http.request(...) .map((res: Response) => res.json()) .catch((err: any) => err.json()) .map((payload: any) => { type: 'SUCCESS', payload }) .catch((payload: any) => { type: 'FAILURE', payload}) .subscribe((action: Action) => this.store.dispatch(action)); That way both the success and failure responses are converted to JSON and then based upon the success/fail criteria

Response for preflight is invalid (redirect) in angular2/4

五迷三道 提交于 2020-01-01 18:18:16
问题 I am using angular4 as the frontend and springboot applicaiton as the backend. The integration methods between the frontend and the BFF(backend for frontend) are RESTful requests. So the frontend sends out a POST request to the backend endpoints handled by SpringBoot REST controller, and the the backend return a 302 redirect response to frontend. The problem is that I keep encountering the XMLHttpRequest cannot load https://www.google.ca/. Response for preflight is invalid (redirect) problem.

FirebaseListObservable becomes Observable after query

♀尐吖头ヾ 提交于 2020-01-01 12:12:32
问题 I made a small app on firebase. I have been using a type provided by angularfire called a FirebaseListObservable which allows you to observe changes to your data. The problem I'm having is that Angularfire also provides a way to query the data, by attaching / passing in a query object to the request. The following returns a FirebaseListObservable. this.resources$ = <FirebaseListObservable<IResource[]>> this.af.list(`/resources/${this.auth.id}`) as FirebaseListObservable<IResource[]>; //This

@ngrx/store subscription to part of a store and avoid detecting changes to other parts

≯℡__Kan透↙ 提交于 2020-01-01 11:25:13
问题 Background One of the reducers in my store deals with things that are selected within the app. The interface for this store (let's called it app ) could look like this: interface IApp { selectedProject: IProject; selectedPart: IPart; } So I want to have a subscription that performs an action only when a different 'project' is selected. I wrote something like this: this.store.select('app') .map((store: IApp) => store.selectedProject) .subscribe((project: IProject) => { // Stuff happens here })

Observable retry / retryWhen with flatmap

送分小仙女□ 提交于 2020-01-01 11:14:10
问题 I have the following code to get id and then data related to the id. process(): Observable<any> { let id: number; return this.getId().flatMap( (response: number) => { id = response; return this.getData(id) } ).flatMap( (data: any) => { return Observable.of(data); } ); } getData(id: number): Observable<any> { // retry if response.status is not complete return this.service.getData(id).map(response => return response.data); } I would like to add retry logic on getData method until response

Synchronicity in RxJS

六月ゝ 毕业季﹏ 提交于 2020-01-01 10:14:44
问题 I would expect that the following code would run asynchronously: var range = Rx.Observable.range(0, 3000000); range.subscribe( function(x) {}, function(err) {}, function() { console.log('Completed'); }); console.log('Hello World'); But that's not the case. It takes a while to go through the big range of numbers and only when it is completed the execution is resumed, you can try the code here. I am confused as to when to expect RxJS to behave synchronously or asynchronously. Does it depend on

FormControl debounceTime not available in angular 5 (ionic 3)

一曲冷凌霜 提交于 2020-01-01 10:14:10
问题 I just updated angular in ionic app from version 4 to 5. I have some search FormControl inputs that allow user to search a database via ajax requests. I used debounceTime() method to delay ajax search request but after angular upgrade this method is no longer available. I removed this method call but now a new request is made on every user key press on android. Is there any other way to achieve this delay? this.searchControl.valueChanges .debounceTime(2000) .subscribe(search => this.getCities

Consuming paginated service in Angular2 & Ionic2 using Observables

守給你的承諾、 提交于 2020-01-01 07:23:36
问题 I have a remote collection of interface Foo { id: string; properties: any; } Which I can access using a class FooAPIService { find(skip = 0): Promise<Foo[]> { // promises at most 5 Foos. to get more, use skip > 1 // pagination is server side } on(event: string, callback: (foo: Foo) => any) { // registers event handler, for events: created, updated, removed // events triggered when a change occurs server side } } As a newcomer to Angular2 (and Ionic2), I'm trying to figure out how to consume

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

半城伤御伤魂 提交于 2020-01-01 06:02:01
问题 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?: