rxjs

Method doesn't exists while using in subscribe section of Angular

懵懂的女人 提交于 2021-01-28 21:02:53
问题 Angular: calling two service method with forkJoin Try to process the result in another method in subscription Finally calling another method from process method and getting error, that method doesn't exists Here is the code: onLoad(){ forkJoin([ this.service1.getData(), this.service2.fetchData(id) ]).subscribe( this.processData, errors => { this.error = true; }, () => { this.loading = false; }) }; processData(response: any){ recordA = response[0]; recordB = response[1]; this.validateData

catchError always gets called in HTTP unit testing

拟墨画扇 提交于 2021-01-28 17:53:41
问题 I have a service that makes a HTTP call and I am trying to write tests for it. The method in the service that I am trying to test looks like this // my.service.ts setUserAgreement(accept: boolean): Observable<any> { const data = { accept }; return this.http.post<any>(this.url, data, this.getHttpHeader('1')) .pipe( tap(x => this.logHttp(x)), map(x => this.parseHttp(x)), catchError(this.handleErrorInternal('setUserAgreement')) ); } My test file looks like this import { TestBed, async } from '

catchError always gets called in HTTP unit testing

£可爱£侵袭症+ 提交于 2021-01-28 17:47:58
问题 I have a service that makes a HTTP call and I am trying to write tests for it. The method in the service that I am trying to test looks like this // my.service.ts setUserAgreement(accept: boolean): Observable<any> { const data = { accept }; return this.http.post<any>(this.url, data, this.getHttpHeader('1')) .pipe( tap(x => this.logHttp(x)), map(x => this.parseHttp(x)), catchError(this.handleErrorInternal('setUserAgreement')) ); } My test file looks like this import { TestBed, async } from '

TypeScript generics: Inequivalence of generic function type and call signature of an object literal type (Type 'T' is not assignable to type 'T')

丶灬走出姿态 提交于 2021-01-28 16:31:39
问题 I'm writing an RxJS operator which waits for the input operator to complete and then does a switchMap to a second operator (which is generated on the fly just as with switchMap ). I have come up with two versions of my code, one which works and one which doesn't and I'm struggling to wrap my head around why that is. The version that works: import { Observable } from "rxjs"; // OperatorFunction, import { defaultIfEmpty, last, switchMap } from "rxjs/operators"; // This definition of

Firebase Admin SDK: How to use listUsers() function as Observable combining recursive calls?

岁酱吖の 提交于 2021-01-28 12:43:51
问题 How to use Firebase Admin SDK listUsers() function as an RXJS observable? I can use from RXJS function on listUsers to return an observable, but the challenge is that listUsers returns users in batches. How could these batches of users be retrieved and then merged? 回答1: The Firebase Admin SDK function listUsers could be wrapped with a function that returns an Observable . Then flatMap and forkJoin could be used to combine the recursive function calls into one array of users. import { forkJoin

Firebase Admin SDK: How to use listUsers() function as Observable combining recursive calls?

╄→гoц情女王★ 提交于 2021-01-28 12:43:21
问题 How to use Firebase Admin SDK listUsers() function as an RXJS observable? I can use from RXJS function on listUsers to return an observable, but the challenge is that listUsers returns users in batches. How could these batches of users be retrieved and then merged? 回答1: The Firebase Admin SDK function listUsers could be wrapped with a function that returns an Observable . Then flatMap and forkJoin could be used to combine the recursive function calls into one array of users. import { forkJoin

What is the proper way for binding data to cascade dropdown / autocomplete lists in Angular?

℡╲_俬逩灬. 提交于 2021-01-28 11:14:38
问题 I use mat-autocomplete in several places in my project and fille them as shwon below on form loading: countries: CountryDto[] = []; cities: CityDto[] = []; getCountries() { this.demoService.getCountries().subscribe((list: CountryDto) => { this.countries = list; }); } getCities(countryId) { this.demoService.getCities(countryId).subscribe((list: CityDto) => { this.cities= list; }); } However, when I tried to use a second list as cascade, I cannot make the second one to fill according to the

Transform data in an Observable

倖福魔咒の 提交于 2021-01-28 09:43:25
问题 I'm retrieving a list of items from an Observable on my Angular service. Inside every item, I have an array with a list of subjects. For every subject, I need to make another call to get its details (e.g. name, description, etc.). Data structure: - post1 - subjects: ['books', 'cars', 'movies'] With that list, I have the id from every subject but I need to return an observable containing all subjects belonging to that post (and their details). AppService.ts getPost(id: string): Observable<Post

Transform data in an Observable

天大地大妈咪最大 提交于 2021-01-28 09:42:04
问题 I'm retrieving a list of items from an Observable on my Angular service. Inside every item, I have an array with a list of subjects. For every subject, I need to make another call to get its details (e.g. name, description, etc.). Data structure: - post1 - subjects: ['books', 'cars', 'movies'] With that list, I have the id from every subject but I need to return an observable containing all subjects belonging to that post (and their details). AppService.ts getPost(id: string): Observable<Post

Marble testing observable that changes after a method call?

淺唱寂寞╮ 提交于 2021-01-28 09:34:01
问题 In Angular 8, I have a service with a readonly Observable property, spawned from a BehaviorSubject<string> that contains a string describing the service's state. Also in the service are methods that change the state of the service. export class StateService { private _state = new BehaviorSubject<string>('before'); readonly state$ = this._state.asObservable(); constructor () { } begin() { this._state.next('during'); } finish() { this._state.next('after'); } reset() { this._state.next('before')