Skip to content

GravionLabs/elysion / .agents/skills/angular-developer

angular-developer

Verified

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, services, or HTTP communication, or for best practices on reactivity (signals, linkedSignal, resource, httpResource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, naming conventions, or CLI tooling.

FileKindSize
SKILL.mdskill md10.5 KB
references/angular-animations.mdmarkdown3.9 KB
references/angular-aria.mdmarkdown18.2 KB
references/cli.mdmarkdown3.6 KB
references/component-harnesses.mdmarkdown2.7 KB
references/component-styling.mdmarkdown2.5 KB
references/components.mdmarkdown3.8 KB
references/creating-services.mdmarkdown3.2 KB
references/data-resolvers.mdmarkdown1.6 KB
references/define-routes.mdmarkdown2.1 KB
references/defining-providers.mdmarkdown2.2 KB
references/di-fundamentals.mdmarkdown3.4 KB
references/e2e-testing.mdmarkdown884 B
references/effects.mdmarkdown2.7 KB
references/environment-configuration.mdmarkdown3.3 KB
references/hierarchical-injectors.mdmarkdown2.1 KB
references/host-elements.mdmarkdown2.1 KB
references/http-client.mdmarkdown5.4 KB
references/injection-context.mdmarkdown1.9 KB
references/inputs.mdmarkdown2.4 KB
references/linked-signal.mdmarkdown2.6 KB
references/loading-strategies.mdmarkdown1.5 KB
references/mcp.mdmarkdown3.2 KB
references/migrations.mdmarkdown2.0 KB
references/naming-conventions.mdmarkdown5.4 KB
references/navigate-to-routes.mdmarkdown1.6 KB
references/outputs.mdmarkdown2.6 KB
references/pipes.mdmarkdown3.8 KB
references/reactive-forms.mdmarkdown3.5 KB
references/rendering-strategies.mdmarkdown1.8 KB
references/resource.mdmarkdown3.9 KB
references/route-animations.mdmarkdown1.6 KB
references/route-guards.mdmarkdown1.8 KB
references/router-lifecycle.mdmarkdown1.5 KB
references/router-testing.mdmarkdown3.7 KB
references/show-routes-with-outlets.mdmarkdown1.6 KB
references/signal-forms.mdmarkdown27.2 KB
references/signals-overview.mdmarkdown2.8 KB
references/tailwind-css.mdmarkdown1.8 KB
references/template-driven-forms.mdmarkdown3.7 KB
references/testing-fundamentals.mdmarkdown2.5 KB

references/di-fundamentals.md

View on GitHub
# Dependency Injection (DI) Fundamentals

Dependency Injection (DI) is a design pattern used to organize and share code across an application by allowing you to "inject" features into different parts. This improves code maintainability, scalability, and testability.

## How DI Works in Angular

There are two primary ways code interacts with Angular's DI system:

1.  **Providing**: Making values (objects, functions, primitives) available to the DI system.
2.  **Injecting**: Asking the DI system for those values.

Angular components, directives, and services automatically participate in DI.

## Services

A **service** is the most common way to share data and functionality across an application. It is a TypeScript class decorated with `@Service()`.

### Creating a Service

Use the `@Service()` decorator to make the service a singleton available throughout the entire application. This is the recommended approach for most services.

```ts
import {Service} from '@angular/core';

@Service()
export class AnalyticsLogger {
  trackEvent(category: string, value: string) {
    console.log('Analytics event logged:', {category, value});
  }
}
```

Common uses for services include:

- Data clients (API calls)
- State management
- Authentication and authorization
- Logging and error handling
- Utility functions

## Injecting Dependencies

Use Angular's `inject()` function to request dependencies.

### The `inject()` Function

You can use the `inject()` function to get an instance of a service (or any other provided token).

```ts
import {Component, inject} from '@angular/core';
import {Router} from '@angular/router';
import {AnalyticsLogger} from './analytics-logger.service';

@Component({
  selector: 'app-navbar',
  template: `<a href="#" (click)="navigateToDetail($event)">Detail Page</a>`,
})
export class Navbar {
  // Injecting dependencies using class field initializers
  private readonly router = inject(Router);
  private readonly analytics = inject(AnalyticsLogger);

  navigateToDetail(event: Event) {
    event.preventDefault();
    this.analytics.trackEvent('navigation', '/details');
    this.router.navigate(['/details']);
  }
}
```

### Where can `inject()` be used? (Injection Context)

You can call `inject()` in an **injection context**. The most common injection contexts are during the construction of a component, directive, or service.

Valid places to call `inject()`:

1.  **Class field initializers** (Recommended)
2.  **Constructor body**
3.  **Route guards and resolvers** (which are executed in an injection context)
4.  **Factory functions** used in providers

```typescript
import {Component, Directive, Service, inject, ElementRef} from '@angular/core';
import {HttpClient} from '@angular/common/http';

// 1. In a Component (Field Initializer & Constructor)
@Component(/* ... */)
export class Example {
  private service1 = inject(MyService); // ✅ Field initializer

  private service2: MyService;
  constructor() {
    this.service2 = inject(MyService); // ✅ Constructor body
  }
}

// 2. In a Directive
@Directive({
  /*...*/
})
export class MyDirective {
  private element = inject(ElementRef); // ✅ Field initializer
}

// 3. In a Service
@Service()
export class MyService {
  private http = inject(HttpClient); // ✅ Field initializer
}

// 4. In a Route Guard (Functional)
export const authGuard = () => {
  const auth = inject(AuthService); // ✅ Route Guard
  return auth.isAuthenticated();
};
```
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall