rxjs5

Angular 2 - Sort list from Observable

让人想犯罪 __ 提交于 2019-12-03 05:03:14
What is the best way to sort a list of items coming from an Observable and still be able to use the async pipe ? (I read that making a custom sort pipe is not really efficient.) I want to avoid subscribing and keeping a local copy of data and thus just using async pipe... //can I use map here and filter items right in the observable and get rid of subscribe? this.test$ = Observable.of(['one', 'two', 'three']) .subscribe((data) => { data.sort((a, b) => { return a < b ? -1 : 1; }); this.data = data; }); template: <div *ngFor='let item of data'> <!-- want to be able to use async pipe here --> If

Difference between audit and debounce in rxjs?

旧时模样 提交于 2019-12-03 04:37:02
I am reading the offical documentaion of rxjs and then i realized they both are doing exactly same thing. To me they both seems to exactly similar. Please someone point out difference between them (if any) I'm going to describe the difference between them in terms of their Time versions as that's how I understand them best. Both auditTime and debounceTime will initially start a timer when an event comes in. Both will wait the given amount of time before they emit an event. The difference is that debounceTime resets the timer whenever a new event comes in while auditTime does not. auditTime

How to catch an error on a Request, then open a modal, then retry when modal closes with RxJS

淺唱寂寞╮ 提交于 2019-12-03 00:23:58
I want to make a call to a server that can return an authorization fail (401) with Angular2's HTTP class. The flow of the request should look like that: The user makes a request to the server with myService.getSomething().subscribe() If the server returns a 401: open a modal window asking the user for his credentials. The user successfully log back into the application The modal closes and executes a callback The callback should retry the initial request (myService.getSomething().subscribe()) Here is what I have for the moment: export class MyService { // ... public getSomething(): Observable

How to two-way bind my own RxJS Subject to an [(ngModel)]?

99封情书 提交于 2019-12-02 23:36:08
Is there a short and simple way to pass an RxJS Subject or BehaviorSubject to an an Angular 2 directive for two-way binding? The long way to do it would be as follows: @Component({ template: ` <input type="text" [ngModel]="subject | async" (ngModelChange)="subject.next($event)" /> ` }) I'd like to be able to do something like this: @Component({ template: ` <input type="text" [(ngModel)]="subject" /> ` }) I believe the async pipe is only one-way, so that's not enough. Does Angular 2 provide a short and simple way to do this? Angular 2 uses RxJS too, so I expected there to be some inherent

Counting keypresses per second with angular 2 Rxjs

房东的猫 提交于 2019-12-02 08:00:52
问题 /** * Created by darius on 02/04/16. */ import { Component } from 'angular2/core'; import { Observable } from 'rxjs/Rx'; @Component({ styles: [ require('../../style.css') ], selector: 'keypresses-per-second', template: ` <div class="block"> <input type="text" (keypress)="onKeypress($event)"> {{keypresses}} <br> <input type="text" (keypress)="onKeypressReact($event)"> {{keypressesReactive}} </div> ` }) export class KeypressesPerSecond { ngOnInit() { this.nonReactive(); this.reactiveWay(); } //

Type Error: observable.of is not a function - angular-cli@1.6.3 - rxjs@5.5.x - angular5

断了今生、忘了曾经 提交于 2019-12-02 07:28:45
After upgrading to angular-cli@1.6.3 and converting all the RxJS imports, methods, and operators to the new >5.5 form, I get a type error at run-time saying that Observable.of is not a function. The same error happens with all the methods that are defined as a member of an extension of Observable , for example, Observable.fromEvent . On the other hand, the methods that are defined as stand alone functions, like Observable.combineLatest run properly despite the compiler warns that them don't exists on type Observable . Just to clarify, I had no problems with any operator (after converting them

RxJs Branching If Else Logic

元气小坏坏 提交于 2019-12-02 03:59:55
onSave() { // event handler const save$ = combineLatest(this.configData.data, this.layerService.layerData) .pipe( filter(([configData]) => !_.isEmpty(configData)), take(1), tap(_ => this.loadingService.showLoading()), map(data => this.createSaveConfig(data)), flatMap(dataJSON => this.saveService.save(dataJSON)), ).share(); const saveAndReload$ = save$.pipe( filter(_ => !this.savedId), pluck('savedId'), flatMap(savedId => this.saveService.getData(savedId)), tap(reportData => this.retrievedReport = reportData), pluck('savedId'), tap(savedId => { this.savedId = savedId; this.location.replaceState

Counting keypresses per second with angular 2 Rxjs

自古美人都是妖i 提交于 2019-12-02 03:19:27
/** * Created by darius on 02/04/16. */ import { Component } from 'angular2/core'; import { Observable } from 'rxjs/Rx'; @Component({ styles: [ require('../../style.css') ], selector: 'keypresses-per-second', template: ` <div class="block"> <input type="text" (keypress)="onKeypress($event)"> {{keypresses}} <br> <input type="text" (keypress)="onKeypressReact($event)"> {{keypressesReactive}} </div> ` }) export class KeypressesPerSecond { ngOnInit() { this.nonReactive(); this.reactiveWay(); } // not reactive keypresses = ''; counter = 0; secondsPassed = 0; nonReactive(){ var self = this; var int

Subject vs AnonymousSubject

别等时光非礼了梦想. 提交于 2019-12-01 20:27:39
问题 What's the difference between Subject and AnonymousSubject in RxJS 5 ? I've searched the internet but didn't find any info about AnonymousSubject . I've found an example on the web Subject.create(observer, observable); Looking into rxjs source code I saw that this creates and AnonymousSubject . Can you also come up with an example when is good to use AnonymousSubject ? 回答1: The AnonymousSubject doesn't subscribe itself to the source Observable. It just connects the source and destination . I

Why switchMap does not cancel previous observer?

做~自己de王妃 提交于 2019-12-01 13:12:16
I have method described in component (controller): public requestPassportData(): void { const th = this; const data = { get_scanned_data: true }; Observable.timer(0, 1000) .switchMap(() => this.requestMethods.requestPassportData(data)) .takeWhile(() => { return ( th.formRegister.currentForm().index == 1 || th.formRegister.currentForm().index == 2 || th.formRegister.currentForm().index == 3 ); }) .subscribe(response => {}); } If to call method requestPassportData() five times, it will send each second five request to server. Why switchMap does not cancel last observer? Because every time you