Component Authoring
How a component declares itself and its contract: metadata, inputs, outputs and model(), queries, projection, lifecycle, styles and creation from code. Interviewers probe each part.
part ofAngularoverview, primer and where to startread it →on this pageshowhide
explore
- Selectors & Metadata4 questions
- Inputs & Transforms5 questions
- Outputs & Custom Events4 questions
- Model Inputs4 questions
- View & Content Queries5 questions
- Projection Slots & Selectors4 questions
- Init to Destroy Sequence4 questions
- View Encapsulation Modes5 questions
- Programmatic Creation5 questions
- Custom Element Packaging4 questions
questions
page 2 of 2An Angular chart component must measure its container after rendering: why use afterNextRender rather than ngAfterViewInit, and which phases?
basics
~20 sngAfterViewInit runs mid change detection, per component, and also on the server. afterNextRender runs once after Angular has rendered every component to the DOM, only in the browser; measure in earlyRead and draw in write.
An Angular component adds NO_ERRORS_SCHEMA to its schemas to silence template errors; why is that risky, and when is CUSTOM_ELEMENTS_SCHEMA the right choice?
basics
~10 sNO_ERRORS_SCHEMA turns off Angular's unknown-element and unknown-property checks, so typos and forgotten imports compile and render nothing. CUSTOM_ELEMENTS_SCHEMA only allows dash-named unknown elements and their properties, for hosting real Web Components.
Why does an Angular collapsible panel with expanded = model(false), bound one-way as [expanded]="allOpen()", stop reopening on 'expand all' after a user collapses it?
basics
~20 sThe collapse was a child-side write the one-way binding never reported, so the parent still holds true; setting true again changes nothing, so Angular writes nothing. Keep per-panel state in the parent and bind [( )].
An Angular rating component declares an output named change; why does the parent's (change) handler run twice, once receiving a DOM Event instead of the rating?
basics
~20 sAn event binding on a component's element subscribes to its matching output and also adds a native DOM listener. The inner radio's native change bubbles to the host, so the handler runs with the number, then with the Event.
Why does an Angular card that wraps <ng-content select="[card-body]"> in @if (expanded()) still create the projected body, and how do you make it lazy?
basics
~20 sProjected content belongs to the consumer's view, so Angular creates it, runs its lifecycle and keeps it alive whether or not the card's @if shows the slot. For lazy content, have the consumer pass an <ng-template> and render it only when expanded.
Why does an Angular tabs component using contentChildren(Tab) show no tabs when a consumer wraps the <app-tab> elements in a <div>, and how do you fix it?
basics
~20 scontentChildren() and @ContentChildren match only direct children of the host by default, and a wrapping <div> makes the tabs grandchildren. Set descendants: true, which still stops at other components' templates, or keep tabs as direct children.
Why can't an Angular wrapper component's Emulated styles restyle the internals of a third-party date picker it contains, and what are the options and their leakage risks?
basics
~20 sThe picker's cells are created by its own template or code, so they lack the wrapper's _ngcontent attribute. Prefer the library's theming API; otherwise a class-scoped global rule, or :host ::ng-deep as a discouraged, host-bounded last resort.
Why was ComponentFactoryResolver removed in Angular 22, and how do you migrate code that still uses it?
basics
~20 sSince Ivy, a component class carries its own compiled definition, so the factory lookup became redundant; ComponentFactoryResolver was deprecated in v13 and removed in v22. Pass the class straight to ViewContainerRef.createComponent or the standalone createComponent.
When code holds an Angular component instance, how do you subscribe to its output() programmatically, and when must you call unsubscribe on the OutputRefSubscription?
basics
~10 sCall instance.rated.subscribe(callback), which returns an OutputRefSubscription. Angular drops the listener when the component is destroyed, so call unsubscribe() only when the listener's owner goes away first or subscribes repeatedly.
In Angular, how do you give an <ng-content> slot fallback content, and when exactly does the fallback render instead of projected nodes?
basics
~20 sWrite the default markup inside the <ng-content> element itself, supported since Angular 18. It renders only when no node was assigned to that slot when the content was created; a projected @if block counts as assigned even while false.
In Angular, how does a @ViewChildren QueryList report result changes, and what replaces that with the viewChildren() signal query?
basics
~20 s@ViewChildren and @ContentChildren fill a QueryList whose changes Observable emits when the matches change, not the initial set. viewChildren() and contentChildren() instead return a signal of a readonly array that notifies computed() and effect() dependants.
When embedding several Angular Elements widgets in a non-Angular site, what drives their bundle and runtime cost, and how do you keep it down?
basics
~20 sEvery Angular Elements bundle carries the Angular runtime it needs, so separately built widgets duplicate the framework and each bootstraps its own application. Build them together, register all from one createApplication() injector, stay zoneless, and import only what the widgets use.
An Angular Elements feedback widget in a CMS page misses the 'ready' output it emits in ngOnInit and loses its inputs after the CMS detaches and re-attaches it; why?
basics
~20 sConnecting the element creates the component and runs ngOnInit synchronously during insertion, so a listener added afterwards misses 'ready'. Removal destroys the component after a short timer; reconnecting later builds a fresh instance and does not replay earlier inputs.
In an Angular 22 app, part of a page loses its styling after a ViewEncapsulation.None component is destroyed; what explains it, and how do you fix it?
basics
~20 sAngular removes a component's styles from the DOM once no instance using them remains, and v22 extended removal to styles whose host is dropped. Rules a None component carried for other DOM vanish with it; move them to a global stylesheet.
showing 31–44 of 44