Category : rxjs-pipeable-operators

I’m iterating over a object array obtained from a service with ‘NgFor’. At first I updated the object array variable inside subscribe method, and I realize two things. this._myService.sendRequest(input).subscribe((value: SomethingInterface[]) => { this.objectArray = value.map((v) => new Something(v)) }); First: (advantage) If I do a new request the old value is keeped until I receive ..

Read more

So, I was utilizing shareReplay(1) to cache the array of Items in memory that are returned from an HttpClient GET call. if (!this.getItems$) { this.getItems$ = this.httpClient .get<Item[]>(url, options) .pipe(shareReplay(1)); } return this.getItems$; I’m doing this because I have many components on the page that need the array of Items and I don’t want to ..

Read more

I am getting dynamic values as array format like this var sections = [ { id: "1", section: "I", group: "Section1"}, { id: "2", section: "I", group: "Section1"}, { id: "3", section: "I", group: "Section2"}, { id: "4", section: "I", group: "Section2"}, { id: "5", section: "II", group: "Section3"}, { id: "6", section: "III", group: ..

Read more

Hi I am having an angular 5 project and rxjs library used. i have code snippet below. I would like to rewrite in a better way. export class AccountDetailsComponent implements OnInit { ngOnInit() { this.route.paramMap .pipe( tap(paramMap => { this.id = paramMap.get(‘id’) }), switchMap(paramMap => forkJoin( this.accountsService.get(paramMap.get(‘id’)).pipe( catchError(error => { this.notFoundService.checkStatus(error); return _throw(error); }) ), ..

Read more

I don’t understand how to solve an issue in the following scenario: getPosts(): Observable<Post[]> { return this.http.get<Post[]>(this.postsUrl).pipe( tap(() => console.log(‘fetched posts’)), catchError(this.handleError<Post[]>(‘getPosts’, [])) ); } ……. export const mapYearWeek = (post: Post): Post => { post.time = ` ${moment(parseInt(post.time)).year()} -${moment(parseInt(post.time)).week()} `; return post; }; ……… ngOnInit(): void { this.postService .getPosts() .pipe( mergeMap(res => res.map(mapYearWeek(post: Post))), ..

Read more

I’m trying to use below simplified version of my http request pipeline to ensure that if my response does not have the required data in res.myCondition to utlize repeatWhen and make another call, but I’m clearly not utilizing repeatWhen the way it’s meant to be. (angular 8/ rxjs 6.5) Intention is for the first call ..

Read more