skip to content

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 pageshow

explore

questions

page 2 of 2

An Angular chart component must measure its container after rendering: why use afterNextRender rather than ngAfterViewInit, and which phases?

level: seniorimportance: should knowfreq 46%

basics

~20 s

ngAfterViewInit 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.

open as a page

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?

level: seniorimportance: should knowfreq 34%

basics

~10 s

NO_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.

open as a page

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?

level: seniorimportance: should knowfreq 30%

basics

~20 s

The 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 [( )].

open as a page

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?

level: seniorimportance: should knowfreq 30%

basics

~20 s

An 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.

open as a page

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?

level: seniorimportance: should knowfreq 46%

basics

~20 s

Projected 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.

open as a page

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?

level: seniorimportance: should knowfreq 35%

basics

~20 s

contentChildren() 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.

open as a page

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?

level: seniorimportance: should knowfreq 50%

basics

~20 s

The 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.

open as a page

Why was ComponentFactoryResolver removed in Angular 22, and how do you migrate code that still uses it?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

Since 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.

open as a page

When code holds an Angular component instance, how do you subscribe to its output() programmatically, and when must you call unsubscribe on the OutputRefSubscription?

level: middleimportance: nice to knowfreq 28%

basics

~10 s

Call 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.

open as a page

In Angular, how do you give an <ng-content> slot fallback content, and when exactly does the fallback render instead of projected nodes?

level: middleimportance: nice to knowfreq 26%

basics

~20 s

Write 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.

open as a page

In Angular, how does a @ViewChildren QueryList report result changes, and what replaces that with the viewChildren() signal query?

level: middleimportance: nice to knowfreq 28%

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.

open as a page

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?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

Every 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.

open as a page

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?

level: seniorimportance: nice to knowfreq 18%

basics

~20 s

Connecting 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.

open as a page

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?

level: seniorimportance: nice to knowfreq 18%

basics

~20 s

Angular 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.

open as a page

showing 31–44 of 44