rxjs

How to convert a Subject variable to an Observable variable

╄→尐↘猪︶ㄣ 提交于 2019-12-25 08:42:07
问题 Let me explain. Here is my HTML to display my messages like this: <message *ngFor="let message of thread.messages | async" [message]="message"> </message> My thread.messages variable is an Observable. export class Thread { id: string; messages: Observable<Message[]> = new Observable<Message[]>(); } In my addNewMessage() function, I created a Subject variable to add the new messages in: subjectMessages: Subject<Message[]> = new Subject<Message[]>(); addNewMessage(objMessage: any) : void {

Angular 2 Observable to Observable []

我怕爱的太早我们不能终老 提交于 2019-12-25 08:32:10
问题 Not sure if the title is accurate as not sure of the exact terminology. Suppose I have some code like the the below. When I load an individual resource using the first method I can create an instance of a rich model class which wraps/decorates the plain JS object in the function passed to map(...). How can I achieve same in the second method where the response is an array of Course objects? @Injectable() export class CourseService { constructor(private restangular: Restangular) { } public

Angular 2 and RxJS

怎甘沉沦 提交于 2019-12-25 07:59:57
问题 I am trying to build an example realtime app with Angular 2.0.0RC5 and RxJS 5.0.0-beta.6. Although I it is all working with this code: import {IntervalObservable} from 'rxjs/observable/IntervalObservable'; ... return IntervalObservable.create(1000) .flatMap(() => this.http.get('filename.json')) .map(this.extractDataCallBack) .catch(this.handleError); Is this the correct way? The current RxJS api docs seem to specify different methods. Is there a way to upgrade to the latest version of RxJS

How to use rxjs operators inside a TypeScript app

夙愿已清 提交于 2019-12-25 07:37:34
问题 I have a very Typescript app and I want to use rxjs. I did: npm install --save-dev rxjs then in the file main.ts: import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/from'; import 'rxjs/add/operator/filter'; function test() { Observable.from([0,1,2,3,4]) .filter((x) => x >= 2) .subscribe((x) => console.log(x)); } I get a compilation error: Module not found: Error: Cannot resolve module 'rxjs/add/observable/from' In case you need: here is my gulpfile, using Webpack Do you

RxJS5 - How can I cache the last value of a aggregate stream, without using Subjects and whilst excluding those that have completed?

别说谁变了你拦得住时间么 提交于 2019-12-25 07:18:47
问题 I want a pubsub system, with producers and consumers of streams, via a dataplane layer but without Subjects. Many producers can multicast to the same stream name (e.g, 'filters.add'), and multiple consumers can subscribe to the stream. Producers register with a name and stream to create a 'stream of published streams'. If a new producer registers with a particular stream name, the streams flowing to the consumers are dynamically updated such that the data received is a merging of all

How can I load my object in Angular/rxjs that requires 2 API calls

蹲街弑〆低调 提交于 2019-12-25 03:38:05
问题 I am using Angular 6. I have the following classes: export class MyItem{ id: string; name: string; gizmo: Gizmo; }; export class Gizmo{ id: string; name: string; color: string; }; I have to make 2 API calls. 1 - To get the array of MyItems. 2 - To get the gizmo of a given MyItem. I've tried this: this.myItemService.get<MyItem[]>( new FindParameters({ name: name }) ).pipe(tap(z => { z.forEach(function (item) { this.gizmoService.get(item.id) .subscribe(z => { item.gizmo = z; }); }); }))

First view data changes with second API call in angular

做~自己de王妃 提交于 2019-12-25 02:24:15
问题 I am having two views in one component. on left(view) and on right(view2). Left view is already called by API on ngOnInit, when I call second API for view2 , if also changes data in view1. https://stackblitz.com/edit/angular-kendo-2grid On edit service file: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { HttpClient } from '@angular/common/http'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { tap } from 'rxjs/operators/tap';

BehaviorSubject subscriber gets same next() element multiple times

狂风中的少年 提交于 2019-12-25 02:15:36
问题 I'm using a shareData service using BehaviorSubject like the one below. My problem is that every time I call the service's changeMessage method from one component the listener messageSource subscription in any other component is called several times, looks like it received the same message several times. Is this expected behavior? How to prevent it? The service is a singleton. I do not call changeMessage multiple times @Injectable() export class ShareDataService { messageSource = new

AngularFire Rxjs subscription - return nill results

可紊 提交于 2019-12-25 01:48:34
问题 I have two collections which I need to loop through, I start by geting the users groups, I then loop through each group and get the jobs associated with that group. This works perfectly, but the problem is that if there is no jobs the app stays in a loading state. Here is my code: this.fb .getUsersGroupsAsObservable(user.uid, groupType) // first get the users groups .subscribe(groups => { combineLatest( // for each group get the jobs belonging to that group groups.map(group => this.fb

RXJS/Angular Prevent multiple HTTP on multiple subscribers

不羁岁月 提交于 2019-12-25 01:15:51
问题 I have "mainData" service, it consists of 3 parts: currentPage used by paginator component to switch page. Can be updated at any point. folders contains all folders in the current folder. There are 2 components that use this observable (Types of listing of folder content) files contains all files in the current folder. There are 3 components that use this observable (Types of listing of folder content) The default view is the one without folders, thus I would like not to make unnecessary HTTP