Use `inject()` from `@angular/core` to resolve a dependency from the current Angular injection context. The usual location is a class field initializer: ```ts import { Injectable, inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class UserService { private readonly http = inject(HttpClient); getUser(id: string) { return this.http.get('/api/users/' + id); } } ``` `inject()` is the constructor-equivalent style recommend...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-dependency-injection --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Angular Dependency Injection?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-dependency-injection-agent-skills-standard)More formats (shields.io, HTML) on the badges page.
Use `inject()` from `@angular/core` to resolve a dependency from the current Angular injection context. The usual location is a class field initializer:
```ts
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({ providedIn: 'root' })
export class UserService {
private readonly http = inject(HttpClient);
getUser(id: string) {
return this.http.get('/api/users/' + id);
}
}
```
`inject()` is the constructor-equivalent style recommended for services, components, guards, resolvers, and factory functions. It returns the instance from the active injector, so the dependency still needs a provider. For application-wide services, use a tree-shakable provider such as `@Injectable({ providedIn: 'root' })`.
It also works directly in functional router APIs:
```ts
export const authGuard: CanActivateFn = () =>
inject(AuthService).isAuthenticated();
```
Do not call `inject()` from an arbitrary method or asynchronous callback after the injection context has ended; that causes a “no injection context” error. For an optional dependency, use `inject(Token, { optional: true })`. If code genuinely needs to execute outside a class, guard, or factory, run it explicitly with `runInInjectionContext()` and an `EnvironmentInjector`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!