RxJS Tutorial
Selected Reading
- RxJS - Discussion
- RxJS - Useful Resources
- RxJS - Quick Guide
- RxJS - Working with RxJS & ReactJS
- RxJS - Working with RxJS & Angular
- RxJS - Working with Scheduler
- RxJS - Working with Subjects
- RxJS - Working with Subscription
- RxJS - Operators
- RxJS - Observables
- RxJS - Latest Updates
- RxJS - Environment Setup
- RxJS - Overview
- RxJS - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
RxJS - Working with RxJS & Angular
Working with RxJS & Angular
In this chapter, we will see how to use RxJs with Angular. We will not get into the installation process for Angular here, to know about Angular Installation refer this pnk −
We will directly work on an example, where will use Ajax from RxJS to load data.
Example
app.component.ts
import { Component } from @angular/core ; import { environment } from ./../environments/environment ; import { ajax } from rxjs/ajax ; import { map } from rxjs/operators @Component({ selector: app-root , templateUrl: ./app.component.html , styleUrls: [ ./app.component.css ] }) export class AppComponent { title = ; data; constructor() { this.data = ""; this.title = "Using RxJs with Angular"; let a = this.getData(); } getData() { const response = ajax( https://jsonplaceholder.typicode.com/users ) .pipe(map(e => e.response)); response.subscribe(res => { console.log(res); this.data = res; }); } }
app.component.html
<span> <h3>{{title}}</h3> <ul *ngFor="let i of data"> <p>{{i.id}}: {{i.name}}</p> </ul> </span> <router-outlet></router-outlet>
We have used ajax from RxJS that will load data from this url −
.When you compile the display is as shown below −
![RxJs with Angular](/rxjs/images/rxjs_with_angular.jpg)