Directives & Pipes
Attribute and structural directives, host bindings, hostDirectives composition, ng-template outlets, and built-in and custom pipes. Interviewers probe microsyntax desugaring and pipe purity.
part ofAngularoverview, primer and where to startread it →on this pageshowhide
explore
- Attribute-Level Behavior6 questions
- Asterisk Microsyntax5 questions
- Host Bindings & Listeners5 questions
- Composing Host Behaviors5 questions
- Template Outlets & Containers4 questions
- Built-In Value Formatters5 questions
- Custom Transforms & Purity5 questions
questions
page 2 of 2In an Angular template, how does I18nPluralPipe choose the message for an invoice's item count, and what does # do in the mapping?
basics
~10 sI18nPluralPipe looks for an exact '=n' key first, then the locale's plural category such as 'one', then 'other', and throws if none match. In the chosen message each # is replaced by the number.
In Angular, how do you inject a service into a custom pipe, which injector resolves it, and how many pipe instances does a template create?
basics
~10 sCall inject() in the pipe class; it resolves from the element injector where the pipe is used, then environment injectors, without the host's viewProviders. Each usage in each view gets its own pipe instance.
Since Angular 22, what happens when the same directive appears twice in an element's resolved host directive tree, and when does it still fail?
basics
~20 sAngular 22 de-duplicates it: duplicate host directive matches merge into one instance with combined mappings, and a template selector match beats host directive matches. It fails with NG8024 when merged paths give one binding different aliases.
After an upgrade to Angular 21, `@HostListener('click') onClick(e: MouseEvent)` fails the build with "Expected 1 arguments, but got 0."; what changed, and what is the right fix?
basics
~20 sSince Angular 21 the typeCheckHostBindings compiler option defaults to true, so host bindings and listeners are type-checked. The method expects an event but the decorator passes none; add ['$event'] to the decorator, or move to the host object.
With Angular's NgTemplateOutlet, what happens to the rendered view when the context object changes versus when the template or injector input changes?
basics
~20 sA new template or injector makes NgTemplateOutlet destroy the embedded view and create a new one, losing child state. A new context object keeps the view: a Proxy forwards reads to whatever object is currently bound.
showing 31–35 of 35