rxjs

Rxjs Subject next or onNext

自古美人都是妖i 提交于 2019-12-22 04:06:31
问题 I'm quite new at rxjs stuff be patience. For example in this tutorial http://blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services-pitfalls-to-avoid/ but I saw the same code in the ng-book I can see let subject = new Rx.Subject(); subject.subscribe(value => console.log('Received new subject value: ')) subject.next(newValue); but if I put the code in the browser I've got s ubject.next is not a function so if I take a look to the doc https://github.com

Is there an “async” version of filter operator in RxJs?

心不动则不痛 提交于 2019-12-22 03:49:04
问题 I need to filter entries emitted by an observable by checking the entry against some web service. The normal observable.filter operator is not suitable here, as it expects the predicate function to return the verdict synchronously, but in this situation, the verdict can only be retrieved asynchronously. I can make shift by the following code, but I was wondering whether there is some better operator I can use for this case. someObservable.flatmap(function(entry) { return Rx.Observable

Example RxJS Observable when mouse or click activity Re-starts

爷,独闯天下 提交于 2019-12-22 01:30:31
问题 I'm able to create 2 observables to watch mouse move and click events as such: var mousemove$ = Rx.Observable.fromEvent(document, 'mousemove'); var click$ = Rx.Observable.fromEvent(document, 'click'); I'm also able to use merge() and debounceTime() to wait for either mousemove or click to not happen for 10 seconds like this: var allactivity$ = Rx.Observable.merge( mousemove$.mapTo('Mouse!'), click$.mapTo('Click!') ); var lastact$ = allactivity$.debounceTime(10000); However, I would like to

Stream JSON with RxJS Observable

不羁岁月 提交于 2019-12-22 01:17:01
问题 I'm trying to understand a few things about RxJs. What I would like to do is consume some JSON data and immediately begin to render that data on the DOM as it's coming in. I've setup the stream request, response, and display. It's outputting every just fine but it's doing it all at once and not over time. I want to start showing the data on the page as its coming in, instead of waiting for the whole file to complete then show at once which would create a long wait time. //Cache the selector

Best way to share an array between two components using a service in Angular2?

半腔热情 提交于 2019-12-21 23:19:30
问题 I'm developing an app in which there is a component (RecordSelectorComponent) where the user can select multiple records from a grid. The RecordSelectorComponent is nested in SharedAttributesComponents, which is nested in a WizardComponent, and that is nested in a ModalComponent. So the hierarchy looks like this: RecordSelector -(nested in)-> SharedAttributes -> Wizard -> Modal -> App I would like the RecordSelectorComponent to be able to share its list of selected records with the top-level

How to keep observable alive after error in RxJS 6 and Angular 6

限于喜欢 提交于 2019-12-21 21:41:24
问题 Can anyone help with the scenario where this._getReactions$.next() not working whenever this.http.get(...) gets an error. I want to keep observable alive to take the next input. private _getReactions$: Subject<any> = new Subject(); constructor() { this._getReactions$ .pipe( switchMap(() => { return this.http.get(...) // http request }), catchError(error => { console.log(error); return empty(); }) ) .subscribe(data => { console.log(data) //results handling }); } onClick() { this._getReactions$

How to abort an Ajax request from an Observable?

北城以北 提交于 2019-12-21 21:14:03
问题 My code contains this simple function I'm using to upload files to my PHP server (there's an xhr request nested in an RxJS/Observable ): fileUpload(file: File): Observable<any> { return new Observable( observer => { let xhr:XMLHttpRequest = new XMLHttpRequest(); xhr.onreadystatechange = () => { if (xhr.readyState === 4) { if (xhr.status === 200) { observer.next(<any>JSON.parse(xhr.response)); } else { observer.error(xhr.response); observer.complete(); } } }; xhr.open('POST', '__BACKEND__

Get string value from Observable<string> in typescript and Angular

余生长醉 提交于 2019-12-21 18:00:09
问题 I want to get string value from Observable and return the value from the function to the caller function. For eg: I have array of keys and would like to fetch the value (string) of all key one by one and display it html component which has menu bar. Here are the ts files: key-list.component.ts public data = [ { 'key': 1, 'value' : this.getValue(1)}, { 'key': 2, 'value' : this.getValue(2)}, ... ]; private getValue(key: number): string { return this.keyService.find(key).subscribe(response => {

angular2 / RxJS - how to retry from inside subscribe()

老子叫甜甜 提交于 2019-12-21 17:35:13
问题 this is my code: this._api.getCompanies().subscribe( res => this.companies = JSON.parse(res), exception => {if(this._api.responseErrorProcess(exception)) { // in case this retured TRUE then I need to retry() } } ) in case an exception happened, it will be sent to a function in the API then return true if the problem is fixed (like token refreshed for example) and it just needs to retry again after its fixed I could not figure out how to make it retry. 回答1: In your .getCompanies() call right

ng websocket

爱⌒轻易说出口 提交于 2019-12-21 17:12:32
ng使用websocket 1.安装依赖库 npm install ws --save 2.安装类型定义文件 npm install @types/ws --save 3.编写服务 import { Injectable } from '@angular/core'; import {Observable} from "rxjs/Observable"; @Injectable() export class WebSocketService { ws:WebSocket; constructor() { } createObservableSocket(url:string):Observable<any>{ this.ws=new WebSocket(url); return new Observable( observer=>{ this.ws.onmessage=(event)=>observer.next(event.data); this.ws.onerror=(event)=>observer.error(event); this.ws.onclose=(event)=>observer.complete(); } ) } sendMessage(msg:string){ this.ws.send(msg); } } 4.在控制器中使用 import {