Angular Typescript Interview Question Answers Part 2

Angular Interview Questions – Part 2 (Advanced)


21. What is Change Detection in Angular?

Answer: Change Detection is the mechanism Angular uses to update the UI when data changes.

How it works:

  • Angular checks component data
  • Updates DOM if data changed

Strategies:

  • Default → checks everything
  • OnPush → checks only when input changes (better performance)

22. What is OnPush Change Detection?

Answer: OnPush improves performance by reducing unnecessary checks.

When Angular updates UI:

  • Input reference changes
  • Event occurs
  • Observable emits value

Used in: Large, high-performance applications.


23. What is Lazy Loading in Angular?

Answer: Lazy Loading loads modules only when required, not at app startup.

Benefits:

  • Faster initial load
  • Better performance
  • Optimized memory usage

Example use case: Admin module loads only after login.


24. What is Eager Loading vs Lazy Loading?

Answer:

Eager Loading Lazy Loading
Loads at startup Loads on demand
Slower startup Faster startup
Simple apps Large apps

25. What is RxJS?

Answer: RxJS is a library for reactive programming using Observables.

Why Angular uses RxJS:

  • Handles async operations
  • Event-based programming
  • Stream of data over time

26. Observable vs Promise

Answer:

Observable Promise
Multiple values Single value
Can cancel Cannot cancel
Lazy execution Executes immediately

Interview tip: Angular prefers Observables.


27. What is Subject in RxJS?

Answer: A Subject is both:

  • Observable (can be subscribed)
  • Observer (can emit values)

Used for:

  • Event broadcasting
  • Component communication

28. What is BehaviorSubject?

Answer: BehaviorSubject is a Subject that:

  • Requires initial value
  • Always emits latest value to new subscribers

Use case: User authentication state.


29. What is Async Pipe?

Answer: Async pipe automatically:

  • Subscribes to observables
  • Unsubscribes on destroy

Benefits:

  • Avoids memory leaks
  • Cleaner code

30. What is a Memory Leak in Angular?

Answer: Memory leak happens when subscriptions are not unsubscribed.

Common cause: Manual subscriptions without cleanup.

Prevention:

  • Async pipe
  • ngOnDestroy
  • takeUntil

31. What is ngOnDestroy?

Answer: Lifecycle hook used to clean up resources.

Used for:

  • Unsubscribing observables
  • Clearing timers

32. What is ViewChild?

Answer: @ViewChild gives access to DOM elements or child components.

Use case: Focus input, call child methods.


33. What is Content Projection?

Answer: Allows passing HTML content from parent to child using <ng-content>.

Use case: Reusable components like modals, cards.


34. What are Pipes?

Answer: Pipes transform data in templates.

Examples:

  • date
  • uppercase
  • currency
  • Custom pipes

35. What is a Custom Pipe?

Answer: A pipe created by developer for custom transformation.

Example use case: Filter search results.


36. What is Angular Guard?

Answer: Guards control route access.

Types:

  • CanActivate
  • CanDeactivate
  • CanLoad

Use case: Protect routes after login.


37. What is Interceptor?

Answer: HTTP Interceptors intercept API calls.

Used for:

  • Adding auth tokens
  • Logging
  • Error handling

38. What is State Management?

Answer: State management handles shared application data.

Examples:

  • User data
  • Cart items
  • App settings

Popular tools:

  • NgRx
  • Akita
  • Services + RxJS

39. What is NgRx?

Answer: NgRx is a Redux-based state management library for Angular.

Core concepts:

  • Store
  • Actions
  • Reducers
  • Effects

Used in: Large enterprise apps.


40. What is Ahead-of-Time (AOT) Compilation?

Answer: AOT compiles Angular code before browser loads it.

Benefits:

  • Faster rendering
  • Smaller bundle size
  • Better security

🔥 Interview Pro Tips

  • Always mention performance + scalability
  • Explain real-world use cases
  • Use keywords: lazy loading, OnPush, RxJS

0%