rxjs

Add elements to rxjs BehaviorSubject or Subject of an array in Angular2+

无人久伴 提交于 2021-01-28 08:11:52
问题 I was reading up on how to share data between unrelated components in Angular from the "Unrelated Components: Sharing Data with a Service" section of the tutorial here. I see how this example works for the string they are trying to share across their components, but my data type is a little more complex: Namely, I think my BehaviorSubject should look like this: private currentPopulationSource: BehaviorSubject<Population> = new BehaviorSubject<Population>(new Population(new Array<Organism>()))

Padding zip() with undefined

北城余情 提交于 2021-01-28 08:00:08
问题 The following Rx.Observable.zip( Rx.Observable.of(1,2), Rx.Observable.of("a")) .subscribe(p => console.log(p)) produces 1,a which makes sense, but what I want it to produce is 1,a 2,undefined I want to pad the shorter observable with undefineds until the longer one completes. Any suggestions? 回答1: I realise adding delay can turn the .of operator async and with scan you can replace the same value with undefine Rx.Observable.combineLatest( Rx.Observable.of(1,2).delay(0), Rx.Observable.of("a"))

Send HTTPclient post request but dont wait for response and subscribe when backend call sends response back

女生的网名这么多〃 提交于 2021-01-28 07:44:27
问题 I am new to Angular and RxJS operators. I need help in one of the scenario in which I upload multiple documents at once in the backend (Rest API). Processing the documents takes time in backend my my observable gets timeout in 2 minutes. Now I am thinking of the solution in which I will send the post request to backend and will not wait for the response. And subscribe whenever response is ready by backend. Please suggest if my approach is ok ? and how to achieve it in angular 8 with and Rxjs

With RxJS how to trigger observables by another action stream

大兔子大兔子 提交于 2021-01-28 07:10:37
问题 So I am trying to build a list component reactively by angular and RxJS. the list has a lot of features like: search by word change page number change page size filter by field(s) sort search service code: private seachItemSubject = new BehaviorSubject<string>(""); private pageLimitSubject = new BehaviorSubject<number>(10); private pageNumberSubject = new BehaviorSubject<number>(0); private orderingSubject = new BehaviorSubject<ListOrder>({}); private filteringSubject = new BehaviorSubject

Use of EventEmitter in service of Angular6

廉价感情. 提交于 2021-01-28 06:43:08
问题 Why Event Emitter can't use in service in angular 6? In Angular documentation they mentioned, "Use in directives and components to emit custom events" 回答1: Because in services all waht you have to do is manipulating data, if you want to notify the data changes you can use Subjet or BehaviorSubjet . EventEmitter is generally used to notify changes from child to parent and as said is supposed to be used only for @Output . please take a look at this link 来源: https://stackoverflow.com/questions

Type error this.httpClient.get(…).pipe is not a function

ε祈祈猫儿з 提交于 2021-01-28 06:10:26
问题 Update - error solved I solved this error by issuing command: webpack --config webpack.config.vendor.js If however anyone wishes to explain to me why was webpack --config necessary I would gladly upvote and accept your answer. When must I reconfigure webpack - any time I update any of the npm packages or dependencies? Original question I'm following the Tour of Heroes and got stuck at the final chapter "Http", at this step. When I go and try to fetch my hero list I get an error in Chrome

How to mock RxJs Observable Websocket for Unit Tests

元气小坏坏 提交于 2021-01-28 05:45:45
问题 I am creating a web app unsing Angular 4 and RxJs. In one part of my code I am creating a websocket using: Observable.websocket(url); function. Here is my code: /** * Tries to open a websocket connection to a given URL. * @param url * @param subscription Previous subscription to this socket (it may be necessary to close it before proceeding) * @returns an object containing the subscription and the websocket subject. */ private openConnection(url: string, subscription: Subscription): { socket$

Wrapping Promise based JavaScript HTTP client with RxJs Observable

谁都会走 提交于 2021-01-28 01:48:01
问题 I was thinking of using Observables to add .flatMapLatest() & .throttle() functionality to a Promise based HTTP client library (axios). But I'm not going to change the whole application to work with Observables, so I would need something like this: Promise -> Observable -> Promise Anyone managed to do something like this? None of the examples I've found do exactly that. I know that RxJs provides a way to make an Observable from Promise and then convert it back to Promise, but haven't figured

Invoke method when no observers for RxJs Subject

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 20:06:53
问题 How to invoke a method when all the observers have unsubscribed from a subject. Update const alphaStore = new BehaviourSubject(0); observer1 = alphaStore.subscribe(console.log); observer2 = alphaStore.subscribe(console.log); And when all of these observers unsubscribe. I want a method to be invoked. Like... Observer1 unsubscribed Observer2 unsubscribed All observers left 回答1: What you describe already does the finalize() operator. Better said finalize() calls its callback when the chain

How to return data or wait if data loading is still in progress with rxjs

a 夏天 提交于 2021-01-27 19:50:50
问题 I have a service which loads some data in it's constructor with an Observable. Then at some later time the data can be retrieved with a getter. It should return the data right away if it's present. Or wait for loading to finish if that's still in progress. I came up with following example (code is in Typescript): class MyService { private loadedEvent = new Subject<any>(); private loaded = false; private data: any; constructor( private dataService: DataService ) { this.dataService.loadData()