Back to Angular Course

Angular Course

What are Asynchronous Operations?

Observable are used to perform asynchronous operations and handle asynchronous data.

What is the difference between Promise and Observable??

screenshot of the app

What is RxJS?

  • RxJS is a javascript library that allow us to work with asynchronous data stream with the help of observables.
  • Observables are introduced by RxJS library.
  • RxJS stands for Reactive Extensions for Javascript.

What is Observable? How to implement Observable?

Observables are used to stream the data to multiple components.

It is a 3 step process

  • Import Observable from RxJS library.
  • Create Observable and Emit Data.
  • Finally subscribe the Data.

Lets see an example,

app.component.ts

import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrl: './app.component.css' }) export class AppComponent implements OnInit { title = 'Demo'; myObservable = new Observable(observer => { console.log("observable start"); observer.next("a"); observer.next("b"); observer.next("c"); } ); ngOnInit(): void { this.myObservable.subscribe(val =>{ console.log(val); }); } }

What is the role of HttpClient in Angular?

  • HttpClient is a built-in service class available in Angular.
  • Its present in @angular/common/http package.
  • It performs HTTP requests.