Question presented to candidate:
"A directive inside a panel component needs a THEME value. Sometimes it should only use one declared on its own element, sometimes it must ignore its own and use the parent's, and sometimes it should quietly get nothing. Walk me through how Angular searches for a dependency and how @Self(), @SkipSelf(), @Optional() and @Host() change that search."
What a strong answer should cover:
- Default resolution: start at the requesting element's element injector, walk up parent element injectors, then the environment injectors (root, platform), and throw NG0201 at the null injector.
self: look only at the current element's injector, nothing above it.skipSelf: start at the parent, ignoring a provider on the current element (classic use: a nested instance of the same service).optional: returnnullinstead of throwing when nothing is found; combines with the others.host: stop the search at the host component's boundary; inside a component's template it sees the host'sviewProvidersbut not its plainproviders.- Both syntaxes are current: parameter decorators on constructors and
inject(T, { self, skipSelf, optional, host }); the decorators are still public API in Angular 22. providersvsviewProvidersand content projection change what each lookup can see.
Clarifying questions expected:
- "Is the consumer in the component's own template, or projected into it with ng-content?"
- "Should a missing value be an error or a silent fallback?"
Code / implementation expected: Yes β one token provided at several levels and probed with each modifier.