Observables Basics — Angular Technical Interview Questions & Answers

Observables Basics

Observables Basics

  • An Observable is a stream: values over time. HTTP returns one. A search box can emit many. You subscribe, or use async pipe in the template.
  • Board: type in search. debounceTime(300), switchMap to HTTP. Old request cancelled. Trap: nested subscribe inside subscribe — flatten with switchMap. Another trap: forgetting complete/unsubscribe on a long-lived stream.

Technical Interview Tip: Observable vs promise. debounce + switchMap search.

Code Examples for Observables Basics

Observables Basics — working example

import { Component } from "@angular/core";

@Component({
  selector: "app-root",
  template: `
    <h1>{{ title }}</h1>
    <button (click)="toggle()">Toggle</button>
    <p *ngIf="open">Panel open</p>
  `,
})
export class AppComponent {
  title = "Angular practice";
  open = true;
  toggle() {
    this.open = !this.open;
  }
}

Observables Basics: toggle open. Say whether the panel is on screen after one click.

How to Explain Observables Basics to an Interviewer

Observable vs Promise?

Many values over time vs one Cancellable

Why switchMap on search?

Cancel the previous request