Angular Professional Development 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 Professional Development flashcards as text
When using Angular's `Router`, what option must be set to enable preloading of lazy-loaded modules automatically?
Answer: RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
Passing `PreloadAllModules` as the `preloadingStrategy` tells Angular's router to eagerly preload all lazy-loaded route chunks after initial load.
Which RxJS operator is most appropriate when you need to cancel an in-flight HTTP request whenever a new search term is typed?
Answer: switchMap
`switchMap` unsubscribes from the previous inner observable and subscribes to the new one, effectively cancelling the prior HTTP request.
In Angular, what is the default encapsulation strategy for component styles?
Answer: ViewEncapsulation.Emulated
`ViewEncapsulation.Emulated` (the default) adds unique attributes to elements so component styles don't leak, without using real Shadow DOM.
What is the role of `ng-container` in Angular templates?
Answer: Provides a grouping element that adds no extra DOM node
`` is a logical grouping element that Angular removes from the DOM, useful for applying structural directives without adding extra HTML elements.
Which Angular concept allows injecting dependencies at a component level rather than globally, creating a new instance per component tree?
Answer: Component-level providers via the `providers` array in @Component
Listing a service in a `@Component`'s `providers` array creates a scoped injector, giving that component and its children their own service instance.
When writing an Angular custom structural directive, which class must be injected to manipulate the host view container?
Answer: TemplateRef and ViewContainerRef
A structural directive uses `TemplateRef` to reference the embedded template and `ViewContainerRef` to create, insert, or destroy views.
What does the `async` pipe do when the component it's used in is destroyed?
Answer: Automatically unsubscribes to prevent memory leaks
The `async` pipe calls `unsubscribe()` on the observable during the component's `ngOnDestroy` lifecycle hook, preventing memory leaks automatically.