About angular-services
A reference skill for Angular developers building services and using dependency injection. It covers service registration, inject(), factory providers, lazy services, and shared state.
Key features
- 01Register services with providedIn
- 02Inject dependencies with inject()
- 03Configure factory providers
- 04Set up lazy services
- 05Share state through services
Use cases
- 01Creating an application-wide data service
- 02Injecting HTTP or routing dependencies
- 03Configuring a logger with a factory provider
- 04Sharing cart state across components
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ oguzhan18/ angular-ecosystem-skills --skill angular-servicesAfter installing, type/angular-servicesin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
references/discussions/_INDEX.mdreferences/docs/_INDEX.mdreferences/issues/_INDEX.mdreferences/releases/_INDEX.mdDetails
From the project READMEAngular Services
Version: Angular 21 (2025) Tags: Services, @Injectable, DI
References: Services Guide • @Injectable API
Best Practices
- Create service with providedIn
@Injectable({ providedIn: 'root' })
export class DataService {
getData() {
return this.http.get('/api/data');
}
}
- Use inject() function
@Injectable({ providedIn: 'root' })
export class UserService {
private http = inject(HttpClient);
getUsers() {
return this.http.get<User[]>('/api/users');
}
}
- Use factory providers
@Injectable({
providedIn: 'root',
useFactory: () => new LoggerService(environment.production)
})
export class LoggerService {
constructor(private isProduction: boolean) {}
}
- Use providedIn: 'any' for lazy services
@Injectable({ providedIn: 'any' })
export class LazyService {}
- Use service in component
@Component({})
export class MyComponent {
private dataService = inject(DataService);
data$ = this.dataService.getData();
}
- Use multiple services
@Component({})
export class MyComponent {
private auth = inject(AuthService);
private http = inject(HttpClient);
private router = inject(Router);
}
- Use service for shared state
@Injectable({ providedIn: 'root' })
export class CartService {
private items = signal<Item[]>([]);
cartItems = this.items.asReadonly();
addItem(item: Item) {
this.items.update(items => [...items, item]);
}
}
Comments
Markdown supported