Angular Interview questions

Total available count: 96
Subject - JavaScript Frameworks
Subsubject - Angular

What are observable creation functions?

RxJS provides/supplies creation functions for the process of creating observables from things such as promises, events, timers, and Ajax requests. Let us explain each of them with an example as follows,

Create an observable from a promise
import { from } from 'rxjs'; // from function
const data = from(fetch('/api/endpoint')); //Created from Promise
 next(response) { console.log(response); },
 error(err) { console.error('Error: ' + err); },
 complete() { console.log('Completed'); }

Create an observable that creates an AJAX request
import { ajax } from 'rxjs/ajax'; // ajax function
const apiData = ajax('/api/data'); // Created from AJAX request
// Subscribe to create the request
apiData.subscribe(res => console.log(res.status, res.response));

Create an observable from a counter
import { interval } from 'rxjs'; // interval function
const secondsCounter = interval(1000); // Created from Counter value
secondsCounter.subscribe(n =>
  console.log(`Counter value: ${n}`));

Create an observable from an event
import { fromEvent } from 'rxjs';
const el = document.getElementById('custom-element');
const mouseMoves = fromEvent(el, 'mousemove');
const subscription = mouseMoves.subscribe((e: MouseEvent) => {
  console.log(`Coordnitaes of mouse pointer: ${e.clientX} * ${e.clientY}`);


Next 5 interview question(s)

What are the utility functions provided by RxJS?
What is the short hand notation for subscribe method?
How do you perform error handling in observables?
What is multicasting?
What are lifecycle hooks available?