angular-dependency-injection
БесплатноБез исполняемых скриптовНе проверенUse when building modular Angular applications requiring dependency injection with providers, injectors, and services.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Angular Dependency Injection
Master Angular's dependency injection system for building modular, testable applications with proper service architecture.
DI Fundamentals
Angular's DI uses the inject() function (Angular 14+) as the preferred
injection mechanism — no constructor parameters needed:
import { Injectable, inject } from '@angular/core';
// Service injectable at root level
@Injectable({
providedIn: 'root'
})
export class UserService {
private users: User[] = [];
getUsers(): User[] {
return this.users;
}
addUser(user: User): void {
this.users.push(user);
}
}
// Standalone component injection via inject()
import { Component } from '@angular/core';
@Component({
selector: 'app-user-list',
standalone: true,
template: `
@for (user of users; track user.id) {
<div>{{ user.name }}</div>
}
`
})
export class UserListComponent {
private readonly userService = inject(UserService);
users = this.userService.getUsers();
}
Provider Types
useClass - Class Provider
import { Injectable, Provider, Component, inject } from '@angular/core';
// Interface
interface Logger {
log(message: string): void;
}
// Implementations
@Injectable()
export class ConsoleLogger implements Logger {
log(message: string): void {
console.log(message);
}
}
@Injectable()
export class FileLogger implements Logger {
log(message: string): void {
// Write to file
}
}
// Provider configuration
const loggerProvider: Provider = {
provide: Logger,
useClass: ConsoleLogger
};
// Standalone component — providers go here, not in NgModule
@Component({
selector: 'app-my-component',
standalone: true,
providers: [loggerProvider],
template: `...`
})
export class MyComponent {
private readonly logger = inject(Logger);
constructor() {
this.logger.log('Component initialized');
}
}
useValue - Value Provider
import { InjectionToken, Component, inject } from '@angular/core';
// Configuration object
export interface AppConfig {
apiUrl: string;
timeout: number;
retries: number;
}
export const APP_CONFIG = new InjectionToken<AppConfig>('app.config');
// Provider
const configProvider = {
provide: APP_CONFIG,
useValue: {
apiUrl: 'https://api.example.com',
timeout: 5000,
retries: 3
}
};
// bootstrapApplication (standalone)
bootstrapApplication(AppComponent, {
providers: [configProvider]
});
// Usage via inject()
export class ApiService {
private readonly config = inject(APP_CONFIG);
constructor() {
console.log(this.config.apiUrl);
}
}
useFactory - Factory Provider
import { Injectable, InjectionToken, inject } from '@angular/core';
export const API_URL = new InjectionToken<string>('api.url');
// Use inject() inside the factory — no deps array needed
const apiUrlProvider = {
provide: API_URL,
useFactory: () => {
const config = inject(AppConfig);
return config.production
? 'https://api.prod.example.com'
: 'https://api.dev.example.com';
}
};
// Complex factory — all deps resolved via inject()
const httpClientProvider = {
provide: HttpClient,
useFactory: () => {
const handler = inject(HttpHandler);
const logger = inject(Logger);
logger.log('Creating HTTP client');
return new HttpClient(handler);
}
};
useExisting - Alias Provider
import { Injectable, inject } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class NewLogger {
log(message: string): void {
console.log('[NEW]', message);
}
}
// Alias an abstract token to the concrete implementation
export abstract class Logger {
abstract log(message: string): void;
}
const loggerAlias: Provider = {
provide: Logger,
useExisting: NewLogger
};
// Usage
export class MyComponent {
private readonly logger = inject(Logger);
constructor() {
this.logger.log('Using aliased logger');
}
}
Injection Tokens
InjectionToken - Type-Safe Tokens
import { InjectionToken, inject } from '@angular/core';
// Primitive token
export const MAX_RETRIES = new InjectionToken<number>('max.retries', {
providedIn: 'root',
factory: () => 3 // Default value
});
// Object token
export interface FeatureFlags {
enableNewUI: boolean;
enableBeta: boolean;
}
export const FEATURE_FLAGS = new InjectionToken<FeatureFlags>(
'feature.flags',
{
providedIn: 'root',
factory: () => ({
enableNewUI: false,
enableBeta: false
})
}
);
// Usage via inject()
@Injectable()
export class ApiService {
private readonly maxRetries = inject(MAX_RETRIES);
private readonly flags = inject(FEATURE_FLAGS);
}
Hierarchical Injectors
Root Injector
// Singleton across entire app
@Injectable({
providedIn: 'root'
})
export class GlobalService {
private state = {};
}
Component Injector
@Injectable()
export class ComponentServi
Установить angular-dependency-injection в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadFAQ
Что делает скилл angular-dependency-injection?
Use when building modular Angular applications requiring dependency injection with providers, injectors, and services.
Как установить скилл angular-dependency-injection?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл angular-dependency-injection запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic