import Component, OnInit, NgZone from '@angular/core'; @Component( selector: 'app-scroll-tracker', template: ` scrollPosition `, changeDetection: ChangeDetectionStrategy.OnPush ) export class ScrollTrackerComponent implements OnInit { scrollPosition = 0; constructor(private ngZone: NgZone, private cdr: ChangeDetectorRef) {} ngOnInit() this.ngZone.runOutsideAngular(() => window.addEventListener('scroll', () => // High-frequency logic runs silently without triggering change detection this.scrollPosition = window.scrollY; if (this.scrollPosition % 100 === 0) // Explicitly step back into the zone only when needed this.ngZone.run(() => this.cdr.markForCheck(); ); ); ); } Use code with caution. 2. RXJS Advanced Patterns & Memory Management
By default, Angular uses the CheckAlways strategy. Switching to ChangeDetectionStrategy.OnPush disables automatic dirty checking.
Understand the providedIn: 'root' syntax (tree-shakable providers). Modules (NgModule) and Standalone Components
Angular interviews heavily test your asynchronous programming skills. You need to show proficiency in RxJS and demonstrate how Angular Signals change the reactive paradigm. RxJS Higher-Order Mapping Operators
Liked this guide? Share it with your study group. Need more Angular interview hacks? Drop a comment below – I’ll decode specific questions in future articles.
Interviewers frequently present open-ended system design questions. They want to see if you can architect an enterprise Angular application that remains maintainable over years of active development. Enterprise Monorepos and Domain-Driven Design (DDD)
searchTerm$ = new Subject<string>(); results$ = this.searchTerm$.pipe( debounceTime(300), distinctUntilChanged(), switchMap(term => this.api.search(term)) );
He opened the Network tab. The WebSocket frames were encrypted, but the handshake wasn't. He spotted a header: Authorization: Bearer eyJhbGciOi...
Legacy class-based guards ( CanActivate ) are deprecated. Modern Angular uses lightweight functional guards. They leverage the inject() function to fetch services directly inside a flat arrow function configuration. Cross-Site Scripting (XSS) Defenses
Zone.js monkey-patches asynchronous browser APIs (like setTimeout , HTTP requests, and event listeners). It tells Angular when any async event happens, forcing the framework to run change detection top-down across the entire component tree.
Decoded Frontend: The Ultimate Angular Interview Hacking Guide
Modern Angular (v16+) has shifted. If you aren't talking about Standalone Components , your knowledge is considered legacy. The Strategy:
Use @Input() (or input signals) to pass data down from Parent to Child. Use @Output() with an EventEmitter (or output functions) to emit events upward from Child to Parent. For deeply nested components, use a shared, injected service. Q: What is the difference between Promise and Observable ?
Create a search input that queries a backend API as the user types, but avoid overloading the server with requests on every single keystroke.
: Cancels the previous inner observable when a new value arrives. Use for search typeaheads or page navigation.
"If you have two subscribers to an HTTP observable, how many requests are sent?" Answer: Two, because HTTP observables are cold – each subscription triggers execution. Use shareReplay(1) to make it hot and share the response.
Interview Scenario: Implementing a typeahead search box. If a user types a new character, you want to cancel the previous API request immediately.
Historically, Angular relied on zone.js to monkey-patch asynchronous browser APIs (like setTimeout or click events). When any event happened, Zone.js notified Angular to check the entire component tree from top to bottom. This causes significant CPU overhead in large apps.