Angular Advanced Practice Flashcards
7 cards from real Angular Web Framework practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Angular Advanced Practice flashcards as text
Which Angular CDK feature allows you to create custom overlays that are rendered in a portal outside the normal DOM tree?
Answer: Portal
The CDK Portal module lets you render components or templates into a PortalOutlet that lives outside the component's normal DOM position.
What is the purpose of the `APP_INITIALIZER` token in Angular?
Answer: To run initialization logic before the app bootstraps
APP_INITIALIZER accepts factory functions that return Promises or Observables; Angular waits for them to complete before rendering the root component.
In Angular's Ivy renderer, what replaces the old NgFactory files used by View Engine?
Answer: Locality principle compilation with ɵcmp and ɵfac static fields
Ivy uses locality: each class carries its own compiled metadata (ɵcmp, ɵfac, ɵmod) as static fields, eliminating the need for separate NgFactory files.
Which RxJS operator is best suited for switching to a new Observable while cancelling the previous in-flight request, such as in a search typeahead?
Answer: switchMap
switchMap unsubscribes from the previous inner Observable and subscribes to the new one, which cancels any ongoing HTTP request for prior keystrokes.
What does the `trackBy` function in `*ngFor` receive as its two arguments?
Answer: index and item
The trackBy callback receives the loop index and the current item, and should return a unique identifier so Angular avoids re-rendering unchanged DOM nodes.
Which Angular decorator marks a class as an injectable service and specifies where it should be provided?
Answer: @Injectable
@Injectable accepts a `providedIn` property (e.g., 'root') that tree-shakes unused services and registers them in the specified injector.
What is the effect of setting `changeDetection: ChangeDetectionStrategy.OnPush` on a component?
Answer: Only runs change detection when inputs change, an event fires inside the component, or async pipe emits
OnPush skips the component's subtree during global checks unless its inputs have a new reference, an internal event occurs, markForCheck() is called, or an async pipe emits.