rxjs

Wait for Service Api call to complete in Angular 8

ⅰ亾dé卋堺 提交于 2021-02-11 15:26:53
问题 I am trying my first Angular 8 Crud Web app and wrote a page to list some company names from WebApi My Service is correctly getting data and Iam able to print it on console //Service.ts export class CompanyService { allCompanys: Company[] constructor(private httpClient: HttpClient) { } // Returns all the companys GetAll(): Company[] { this.httpClient.get<Company[]>('https://localhost:565656/api/company').subscribe(result => { this.allCompanys = result; //Shows data Sucessfully from Server

Angular 7 Rxjs forkJoin unable to add new Observable to the existing list ie. more than 6 parameters

自作多情 提交于 2021-02-11 14:41:50
问题 I am using rxjs forkjoin to make multiple http request. forkjoin takes 7 parameters To the existing code, i just adding new observable. but for some reason it is throwing error which is really weird. Here is the existing code: const countries = this.referenceDataApiService.getLoadAndDischargeCountries(); const currencies = this.referenceDataApiService.getCurrencies(); ...... forkJoin([countries, currencies,..,..,..,..,xxx]).subscribe((results) => { this.countries = results[0] ? results[0]

Group and debounce observable?

佐手、 提交于 2021-02-11 13:47:37
问题 I have an observable that emits an object which contains a few params. In the object, one of the params (called optionId ) distinctly identifies an option. I'd like to debounce all instances of that emission. However, if a new optionId shows up, I'd like to start a new clock, and start a new debounce. Here's a sample marble diagram for what i'm looking for: -----1----1-----1----3----3----3----3-----1---3---1---3---1------> (magic operators for which I'm unclear) -------------------1----------

How can you Sort a stream by timestamp in Reactivex?

廉价感情. 提交于 2021-02-11 13:37:15
问题 I've combined streams from firestore and now I need to sort them by timestamp (descending) . I really don't know much about reactiveX ...I'm using dartRx. I seen a few solutions using a comparator but not really sure how to use it. Class Order{ Timestamp timestamp; } Stream<List<Order>> sortByTimestamp(){ return combineList(order).....//my stream } 回答1: thanks for your question. Here is my way :) return combineList(order).map((orders) => orders.sort(comparator).toList()); 来源: https:/

How to loop .subscribe observable

一世执手 提交于 2021-02-11 12:22:14
问题 I'm currently trying to make a function where it loops and by using .subscribe I'm getting an array object each time so that later on I can push the data inside an another array. The loop works but the problem is that the results is not what I want because the .subscribe part is printing the first array and then for the rest it's giving me null arrays whereas it suppose to print 20x the same array. I currently started experimenting with angular and to my knowledge of other languages I don't

How to loop .subscribe observable

倖福魔咒の 提交于 2021-02-11 12:21:04
问题 I'm currently trying to make a function where it loops and by using .subscribe I'm getting an array object each time so that later on I can push the data inside an another array. The loop works but the problem is that the results is not what I want because the .subscribe part is printing the first array and then for the rest it's giving me null arrays whereas it suppose to print 20x the same array. I currently started experimenting with angular and to my knowledge of other languages I don't

API polling and timeout

非 Y 不嫁゛ 提交于 2021-02-11 08:52:06
问题 I have a polling use-case where: I want to call an API that, based on business logic, returns numbers(1-10) or error (network issue/ exception in API etc..) instantly (1.5-2 sec). If the API returns an error (network issue/ exception in API etc..) then I want to unsubscribe the polling and display error. If the API returns success, I want to check the return value and un-subscribe(if the return value is 5) or keep the polling going. I want to call API every 5 sec. I want to keep the max time

Async pipe with rxjs

走远了吗. 提交于 2021-02-11 01:11:50
问题 I have a little problem in async pipe Here is my case , I need to run nested observables in async pipe in html because i use on push strategy and i dont want to use some workarounds or change detector reference . My problem is , when i run the code below only the first observable is called Should i add return statements? Or whats the problem ? Ts code this.http.getUsers(criteria) .pipe(map(data=>{ data.users.map(user=>{ this.http.getUserData(user.id) .pipe(map(res=>{user.data=res.data}))}}

Nested Observable/Promise (trying to block/wait flow in mapper function)

喜欢而已 提交于 2021-02-10 22:42:33
问题 I have the following code in an Angular app: services$ .pipe( map(serviceModels => { serviceModels .forEach((srv, srvIdx) => { // Resolve images in services srv.images.forEach(async (img, imgIdx) => { serviceModels[srvIdx].images[imgIdx] = await this.imageSrv.resolveImage(img).toPromise(); }); }); return serviceModels; }); [...] Result is a single emition with one value change afterwards. emit -> service.image[0] // 'unrendered-url' -> (wait) -> service.image[0] // correct-url/image-path I'm

Implementing Session Timeout service for Ionic/Angular, with Timer Reset with each new user interaction

可紊 提交于 2021-02-10 20:39:31
问题 I'm trying to adapt some code I've created for a session timeout. Whenever a user interacts with the function, I want to reset the timer to start counting down again. I'm having difficulty working out how to inject similar code to this example C# code - I'm trying to integrate: var update = new Subject<bool>(); var res = update .Select(x => Observable.Interval(TimeSpan.FromSeconds(10.0))) .Switch(); res .Subscribe(_ => Console.WriteLine("Status sent.")); update.OnNext(true); res .Subscribe(_