rxjs

How to use map and assign the value back

时光毁灭记忆、已成空白 提交于 2019-12-11 04:21:47
问题 I have a list of books, with IsEnable default to False. I need to check each book whether its enabled or not in onInit(). I thought of adding a rxjs map and call the getEligibleBooks() function inside the map, but how to assign the return value true or false in the IsEnable? Books.ts export class Book{ Name:string; IsEnable:boolean; } books.component.ts ... books = Observable.of([{"Name":"A", "IsEnable":"False"},{"Name":"B", "IsEnable":"False"}]); ... getEligibleBooks(book){ //complex logic

How To Wait For an Optional Observable

巧了我就是萌 提交于 2019-12-11 04:13:48
问题 In my Angular application I have am making an optional HTTP call to check if a user exists. Based on the result of this call, I either want to make another call or stop processing. Without resorting to .toPromise() , how can I wait for a call that is made in an if block? onSomeEvent() { const contact: IContact = { ...this.userForm.value }; let cancelProcessing = false; if (this.isNewUser()) { // *** This is optional this.userService.duplicateUserSearch(contact.email, contact.userName)

RxJS combineLatest function can be imported from both rxjs and rxjs/operators, what is the difference between the two?

北慕城南 提交于 2019-12-11 04:06:26
问题 The combineLatest function can be imported either from rxjs and from rxjs/operators . When I import it from rxjs/operators (just like I import combineAll I get the following error: TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<{}, [{}, number, number, number]>' I used the following code snippet: import { timer } from "rxjs"; import { combineLatest } from "rxjs/operators"; const timerOne = timer(1000, 2500); const timerTwo = timer(1500, 2500); const timerThree = timer

Restart the timer on an rxjs interval

你。 提交于 2019-12-11 03:54:33
问题 I created a class which sets up a pausable rxjs observable on an interval: export class RepeatingServiceCall<T> { private paused = false; private observable: Observable<T>; constructor(serviceCall: () => Observable<T>, delay: number) { this.observable = interval(delay).pipe(flatMap(() => (!this.paused ? serviceCall() : NEVER))); } setPaused(paused: boolean) { this.paused = paused; } getObservable() { return observable; } } This seems to work fine but the problem I am trying to solve is that I

combineLatest behaviour in Rxjs 5?

為{幸葍}努か 提交于 2019-12-11 03:52:02
问题 Looking at the definition of combineLatest Combines multiple Observables to create an Observable whose values are calculated from the latest values of each of its input Observables. or Whenever any input Observable emits a value, it computes a formula using the latest values from all the inputs, then emits the output of that formula. It's pretty clear to see that at each period of time / emission , the result at that emission is the combination of the latest emissions. If so , looking at this

Listening for DB data changes in Angular using Rxjs or anything

做~自己de王妃 提交于 2019-12-11 03:44:54
问题 i have a Service in backend (node.js) i am subscribing it through the angular http client service and it is working fine. for my application more than one uers are there. so some other user can change the DB data . so whenever the changes happened to DB data i would like subscribe them immediately. so all users can view the consistent data i.e., data synchronized with DB data. i am using RXJS Observables in angular services. 回答1: Before going into the answer, be aware that fulfilling your

Create infinite repeatable Observable from array

一曲冷凌霜 提交于 2019-12-11 03:44:47
问题 Let's say I have an array items I know I can create an observable from this array using Rx.Observable.fromArray(items) How do I create a lazily infinitely repeating observable from this (i.e.: repeating the items as long as they are being requested)? Tried Rx.Observable.fromArray(items).repeat() But this doesn't execute lazily and therefor locks up the browser. 回答1: You cannot do this with an Observable. You way want to look at using an Enumerable. The Enumerable flavor of Reactive Extensions

Angular 2 - Multiple HTTP request in the same time

橙三吉。 提交于 2019-12-11 03:41:42
问题 I'm actually working on an Angular 2 application but i have a some problems. Indeed, i have a method which get data from a database. However i'm trying to copy this data to an other one, to do that i need to do multiple HTTP request ( the requests number are never the same ). Here is my migrate method. First I get the data from DB and then I try to post them in the other one service.getDatas().subscribe( data => { let datas = data.json().data; if (datas) { let requests = []; for (let data of

How to chain calls to ng2-Translate, and rxjs observables in general?

感情迁移 提交于 2019-12-11 03:24:47
问题 I have just started using the ng2 translate in my Ionic 2 (Angular 2) project. I Have found that when I need to get a few strings all at once, the code becomes nested and a lot harder to read. I am sort of wondering why something like this (that just emits a single value) need to use an observable, but perhaps there is a good reason. Anyway... So for example, say I had 4 strings to read at various points in a method let result1: string; let result2: string; let result3: string; let result4:

Observable of Component Attribute Changes in Angular2

陌路散爱 提交于 2019-12-11 03:02:35
问题 When creating a component in angular 2 that has inputs attributes via @Input, how can I get an observable from the changes made to that attribute @Input (not to be confused with user form input). export class ExampleComponent implement OnChanges{ @Input() userObject: User; ngOnChanges(changes: any): void{ // Validate that its the 'userObject' property first this.doStuff() } } In practice, I would like to merge the Observable changes of the userObject with the Observable changes of other