Explain resolution modifiers in Angular DI.
Skip to solutionKEEP THE
hardFrontend
How does Angular's dependency resolution search work using @Self(), @SkipSelf(), @Optional(), and @Host()?
250 views
01
Understand the problem
didecorators
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Resolution modifiers restrict or modify where the DI injector searches for dependencies: @Self() queries only the current component's injector; @SkipSelf() starts searching from the parent injector; @Host() stops searching at the template boundary; @Optional() prevents throwing an error if the token isn't found
Solution ready — 2 min read
Classified // press E to declassify
04
Read the code
Using resolution modifiers in a component constructor
import { Component, Optional, Self, SkipSelf, Host } from '@angular/core';
@Injectable()
export class LoggerService {}
@Component({
selector: 'app-sandbox',
providers: [LoggerService],
template: '...'
})
export class SandboxComponent {
constructor(
@Self() private localLogger: LoggerService,
@SkipSelf() private parentLogger: LoggerService,
@Host() private hostLogger: LoggerService,
@Optional() private optionalLogger: LoggerService | null
) {}
}05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 115 of 121 decoded in the Angular track. One more won't hurt.