rxjs

How to apply rxjs operator to data got from angularfire2

我怕爱的太早我们不能终老 提交于 2019-12-23 04:21:17
问题 Suppose I requested for data in angularfire2 like this: var ref = new Firebase("firebase url"); Now how can I apply rxjs operator like map operator to the data coming 回答1: I don't think you are looking at angularfire2 there - that's v1 code... You can use the rxjs operators in angularfire2 - the data is returned as an Observable (FirebaseListObservable or FirebaseObjectObservable) - so you can import and apply any of the rxjs operators to those... In general, you just assign the data to a

Observable Map does not cast to typescript class

烈酒焚心 提交于 2019-12-23 03:50:23
问题 I am using angular 2 and I am trying to call an endpoint to return a collection of objects. I have the following TypesScript class export class Route { public branchId: number; public branch: string; public isTest: boolean = true; } I have a api endpoint which returns the following Json [{"id":610,"branch":"Coventry"},{"id":620,"branch":"Shoreham"}] I have a route service which calls the endpoint using the following code public getRoutes(): Observable<Route[]> { const url = 'http://localhost

Property 'map' does not exist on type 'Observable' after upgrading rxjs to 6

僤鯓⒐⒋嵵緔 提交于 2019-12-23 03:39:10
问题 I upgraded my Angular application from version 5.2 to 6.0 with the instructions from https://update.angular.io. Now my Angular application doesn't build because of the "rxjs-5-to-6-migrate" migration: ERROR in bla.ts: error TS2339: Property 'map' does not exist on type 'Observable'. I have the following imports: import { Observable } from 'rxjs/observable'; import { of } from 'rxjs/observable/of'; import { map } from 'rxjs/operators'; If I change the imports like this it works: import {

How to handle request on interceptor after getting the value from an observable on rxjs and angular?

血红的双手。 提交于 2019-12-23 03:15:15
问题 So I'm coming from an AngularJS background while learning Angular 5, I still can't wrap my head around observables. I'm trying to write an HTTP interceptor for my authentication service. However when I try to get a value from the localstorage service (or any observable at this point) I'm not quite sure how to properly return the next.handle(req) method from the observable after getting the data (using subscribe?) Here's my current code (which does not work): @Injectable() export class

How to handle request on interceptor after getting the value from an observable on rxjs and angular?

拈花ヽ惹草 提交于 2019-12-23 03:15:09
问题 So I'm coming from an AngularJS background while learning Angular 5, I still can't wrap my head around observables. I'm trying to write an HTTP interceptor for my authentication service. However when I try to get a value from the localstorage service (or any observable at this point) I'm not quite sure how to properly return the next.handle(req) method from the observable after getting the data (using subscribe?) Here's my current code (which does not work): @Injectable() export class

Why I can't access template DOM element in the constructor of the component

与世无争的帅哥 提交于 2019-12-23 03:03:47
问题 Starting with RxJS and want to create a simple stream of button clicks, so I simply do this: export class AppComponent { button : HTMLElement = document.querySelector('button'); refreshClickStream$ = Observable.fromEvent(this.button, 'click') .subscribe(); constructor(){ } but receive that error in console... Also tried it like this: clicked(e) { return Observable.fromEvent(e.target, 'click') .do(console.log) .subscribe(); } But after first click I get no output in console. After second click

Is there a way to use a observable returning function for each element of another observable array?

喜你入骨 提交于 2019-12-23 02:36:04
问题 I get an Observable<Group[]> from my Firebase collection. In this Group class is an id which I wanna use to retrieve another dataset array from Firebase, which would be messages for each unique group Observable<Message[]> .(each group has its own chat: Message[] ) And it want to return an observable which hold an array of a new Type: return { ...group, messages: Message[] } as GroupWithMessages the final goal should be Observable<GroupWithMessages[]> getGroupWithChat(): Observable

Rxjs Observable Lifecycle

微笑、不失礼 提交于 2019-12-23 02:32:42
问题 If I am ever working with rxjs , I normally, in my component file, keep track of all of my subscriptions by pushing said subscriptions into a Subscription array: private subcriptions: Subscription[]; this.subscriptions.push(this.myObservableOne.subscribe(...)); this.subscriptions.push(this.myObservableTwo.subscribe(...)); public ngOnDestroy(): void { this.subscriptions.forEach(s => s.unsubscribe()); } Now, I am running into something that I thought was interesting. If I instead need to

Fire multiple actions and wait for them to resolve RxJS / Redux Observables

别等时光非礼了梦想. 提交于 2019-12-23 01:52:07
问题 I have an action that I want to use to initialise my app, I want to create an epic for this action and then fire multiple other actions off the back of this, wait for them to all complete and there fire another action. I had a look at other questions and it's pretty similar to this one I've tried this approach and for me, it doesn't work, it fires the APP_INIT action then but then fails to fire any of the other actions in the sequence. Is anyone able to help? import { of } from 'rxjs'; import

Recognizing and exact series of events in RxJS

风格不统一 提交于 2019-12-23 01:45:41
问题 Using RxJS, I want to fire an event if the user types 'a' then 'b' then 'c'. I do not want the event fired if they enter 'a' then 'b' then 'z' then 'c'. Here is my codepen of the work I have done so far (in TypeScript). class App1 { private divStream: HTMLElement; private divResult: HTMLElement; constructor(divStream: HTMLElement, divResult: HTMLElement) { this.divStream = divStream; this.divResult = divResult; } start() { var filterByCharacter = (expectedCharater) => { return (char) => {