rxjs

Angular return value from subscribe

人盡茶涼 提交于 2019-12-24 10:26:06
问题 I need to return value from subscribe of a service call. here is my code export class RideDataSource extends DataSource<any> { rides: Ride[]; constructor(private _rideService: RidesService, private _paginator: MatPaginator) { super(); } connect(): Observable<Ride[]> { this._rideService.getActiveRides(this._paginator.pageIndex, this._paginator.pageSize).subscribe( ridePage => { this.rides = ridePage.content; this._paginator.length = ridePage.totalElements; } ); // i need to return Observable

Observable of array with filter using Angular 5 with RxJS

▼魔方 西西 提交于 2019-12-24 09:39:16
问题 I'm creating a simple forum. I'm looking to filter the posts. I have some trouble with .pipe and .filter in RxJS. I'm trying to: Retrieve the list of in-memory-api posts from api/posts , which when used with http.get it returns an Observable<Post[]> Iterate through each Post in the Observable<Post[]> and filter it so it only selects, says, each post with an id of 1 (only one post with id 1 exists). Log to the console any errors or if the function had success The filter does not select each

RxJs: updating values in a list from an other stream identified by an ID

早过忘川 提交于 2019-12-24 09:12:46
问题 I have two RX infinite streams (let's call them mainValues and decoratorValues ). The one called mainValues are adding elements to a list called valueList . The other stream ( decoratorValues ) should assign properties to these elements in the list. Elements in the two streams are arriving at random times in random order , and I need to solve it in either order that mainValues are put into the list as soon as available , while decoratorValues are not lost until their corresponding elements

RxJs - transform array of Observables to an array of emitted values

雨燕双飞 提交于 2019-12-24 08:59:06
问题 Sorry for the title, I couldn't think of a better one. I've got this piece of code, which basically: filter for valid (non-null) cron epressions' arrays map each cron expression to a call to a service this.formGroup.valueChanges.pipe( op.filter(v => !!v.cronExpressions), op.map((v): string[] => v.cronExpressions), op.map((v: string[]) => v.map(cron => this.cronService.getReadableForm(cron).pipe( op.map(this.toDescription), op.map((description): CronExpressionModel => ({ cron, description }))

Angular 2: How to handle http oauth authtoken 401 errors on a global basis

谁说胖子不能爱 提交于 2019-12-24 08:57:49
问题 I want to use the global error handler to handle access tokens expiring and refreshing them using the refresh token. My solution that almost seems to work is as follows: rom your component, subscribe to an observable as follows: this.myHttpService.getSomeData().subscribe(response => { console.log('user logged in', response ); }, error => { // optionally do something custom here. console.log(error); throw error; // we could handle the error here, getting the new auth token and calling this

Using RxJS how to buffer function calls until an other async function call has resolved

前提是你 提交于 2019-12-24 08:36:49
问题 How can I use RxJS to buffer function calls until another async function has resolved? Here is a simple example of what I'd like to accomplish function asyncFunc(time) { setTimeout(() => { console.log('asyncFunc has resolved'); }, time); } function funcToBuffer(time) { setTimeout(() => { console.log(time); }, time); } asyncFunc(3000); funcToBuffer(1000); funcToBuffer(2000); funcToBuffer(4000); funcToBuffer(5000); asyncFunc(8000); funcToBuffer(6000); funcToBuffer(7000); At the moment this code

Angular 6 String Interpolation not updating with value inside .subscribe()

六月ゝ 毕业季﹏ 提交于 2019-12-24 07:58:12
问题 I have a component that displays the title and artist of a particular video. When I call playNext() in my service, it's supposed to update the title and artist with a new data. I do a console.log and I could verify that the subscription works. I get an updated value everytime playNext() is called, however the value in the template does not get updated. It only displays correctly the first time. Am I missing something? Here is my component code @Component({ selector: 'ntv-now-playing',

Observable subscription not getting called

喜夏-厌秋 提交于 2019-12-24 07:47:43
问题 I have an Observable that I'm using to convert a promise into a subscription. This results in a collection that I need to iterate through to call an HTTP Service on each element. I'm using forkJoin to wait for all those calls to finish so that I can do something else, but unfortunately, my subscription is not being called. Do you see what I'm missing here? Observable.fromPromise(this.users.getElements()).subscribe(results => { Observable.forkJoin( results.map( aUser => this.HttpService

Get Observable references from many to may middle foreign collection

北城余情 提交于 2019-12-24 07:27:31
问题 I have a many to many relationship: [persons]x------1[personsPets]1------x[pets] [persons] id name [pets] id name [personsPets] id personId petId Using @angular/fire and rxjs 6, I want a service to get the persons array with their pets each, like that: this.personService.getPersons().subscribe(persons => { const firstPersonPetNames: string[] = persons[0].pets.map(pet => pet.name) const secondPersonPetNames: string[] = persons[1].pets.map(pet => pet.name) console.log(firstPersonPetNames) // [

Rx.Observable.range is missing in Typescript

纵饮孤独 提交于 2019-12-24 07:25:11
问题 I am trying to use RxJS with Typescript and downloaded everything what I need. Then I wanted to test if the code works: As you can see Rx.Observable.range the range method is marked as red. I look into the Observable.ts and search for range method, it does not find. But it exists under the folder observable a range.ts file. What am I doing wrong? 来源: https://stackoverflow.com/questions/38889155/rx-observable-range-is-missing-in-typescript