rxjs

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

component variables inside a RxJS subscribe() function are undefined

假如想象 提交于 2019-12-22 18:27:44
问题 Variables inside subscribe are undefined but when i put breakpoint before hitting service subscribe I have the variable defined. In Service: getCashierRiskProfiles(): Observable<ICashierRiskProfile[]> { return this.http.get(this._baseUrl + "src/HTTPJson/cashierriskprofile.json") .map((res: Response) => res.json()) .catch((error: any) => Observable.throw(error.json().error || 'Server error')); } In Component: import { Component, OnInit} from "@angular/core"; import { CashierRiskProfileService}

Angular 2 Service + RxJS BehaviorSubject or EventEmitter

倖福魔咒の 提交于 2019-12-22 18:09:26
问题 I am new to Angular 2 and RXJS. I have a custom header component with 2 triggers (buttons) which should activate 2 different navigation directives in different parts of the application. I have created a service which registers the 2 different navigation directives and the header component subscribes to this. I wanted to know whats the best way to link the buttons in the header to call the open() and close() functions in each of the directives depending on the trigger that is clicked. NOTE:

How to create components from a JSON array in cycle js

做~自己de王妃 提交于 2019-12-22 17:55:13
问题 Given the labeled slider component example from the Cycle js web site. How would I take a JSON array of slider information objects and create a labeled slider component for each Object in the array. for example if I had an array like this let labelSliderArray = [ { label: 'Height', unit: 'in', min: 40, max: 84, init: 50 }, { label: 'Weight', unit: 'ibs', min: 40, max: 84, init: 50 }, { label: 'Age', unit: 'years', min: 10, max: 65, init: 20 } ] How would I map each label object to a label

Reset timeout on event with RxJS

ぐ巨炮叔叔 提交于 2019-12-22 14:58:23
问题 I'm experimenting with RxJS (with the JQuery extension) and I'm trying to solve the following use case: Given that I have two buttons (A & B) I'd like to print a message if a certain "secret combination" is clicked within a given timeframe. For example the "secret combination" could be to click "ABBABA" within 5 seconds. If the combination is not entered within 5 seconds a timeout message should be displayed. This is what I currently have: var secretCombination = "ABBABA"; var buttonA = $("

Using pure Observable vs array (from subscribe)

雨燕双飞 提交于 2019-12-22 12:59:32
问题 I was wondering about best practices regard using pure observable vs subscribe to an observable and use an array. option 1 - "pure observable" this.schools = this.angularFire.database.list('schools') and then in the HTML use async pipe (and rxjs operators for handling the data) option 2 - "subscribe to array" this.angularFire.database.list('schools').subscribe (response => this.schools=response) and then treat it as a normal array. 回答1: As olsn pointed out in the comments, it is always more

Angular/rxjs/Subject/BehaviorSubject share http service data across multiple components

不问归期 提交于 2019-12-22 12:37:11
问题 Follow up question to Share data between components using a service in Angular2 and a response I got. I'm trying to share data that a service providers retrieves via a GET. The component structure is as follows with the main routes going to CustomerPortalDashboardComponent and DocumentsComponent <CustomerPortalBaseComponent> <router-outlet> <CustomerPortalDashboardComponent/> <DocumentsComponent/> <router-outlet> </CustomerPortalBaseComponent> CustomerPortalBaseComponent makes a call to get

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

Angular2 router with Http data service through a Resolve with Observable catching 404

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 12:14:46
问题 In my resolve guard I am getting an Http Observable to return the JSON of a user from a particular id . I want to catch an error and reroute to the users overview if the id does not exist. I have seen code that solves that with a Promise, but not with an Observable. I would like to see a solution with an Observable! Currently I get an "EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: http://127.0.0.1:3000/users/191" since user 191 does not exsist. Here is my code

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