Posts

Showing posts with the label #RxJS

Nested API's in Angular

Hi Friends, This is Lakshman here. As part of the Series Angular Best Practices Today, We will Nested API's in Angular . Pre-requisites: The pre-requisites are Node.JS - Click Here Angular CLI - Click Here VS Code - Click Here Nested API's It is a Concept where we may call multiple API at one time or Chaining the API to Call one by one with passing data. The mainly used functions to implement Nested API from rxjs library, forkJoin mergeMap forkJoin It used to call multiple APIs to fetch all data as an array at one time. For example, return forkJoin ([ this . helloService . getData () , this . helloService . getStatus () ]) . pipe ( map (allResponses => { return { Data : allResponses[allResponses . length - 2 ] , Status : allResponses[allResponses . length - 1 ] } ; }) ) ; mergeMap It uses to chain the...

RxJS Subject In Angular

Hi Friends, This is Lakshman here. As part of the Series "Angular Best Practices". Today, We will RxJS Subject in Angular . Pre-requisites: The pre-requisites are Node.JS - Click Here Angular CLI - Click Here VS Code - Click Here RxJS Subject A Subject is like an Observable, Where we can subscribe to information and receives it when new data is available. Now, we are going to see how we could use Subject in Angular. Sent Info between Components. At First, we need a service to define our Subject as below, import { Observable, Subject } from 'rxjs'; private infoSubject = new Subject<any>(); Then we need to set up the method to get Observable, Send and Clear Info as below, import { Observable, Subject } from 'rxjs'; ... onInfo(): Observable<any> { return this.infoSubject.asObservable(); } sendInfo(info: any) { if (info !== undefined) { this.infoSubject.next(info); } } clearInfo() { this.infoSubject.next(); ...