LazyCats-dev/ao3-podfic-posting-helper / .agent/skills/angular-developer
angular-developer
VerifiedGenerates 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.
references/inputs.md
View on GitHub# Inputs
Inputs allow data to flow from a parent component to a child component. Angular recommends using the signal-based `input` API for modern applications.
## Signal-based Inputs
Declare inputs using the `input()` function. This returns an `InputSignal`.
```ts
import {Component, input, computed} from '@angular/core';
@Component({
selector: 'app-user',
template: `<p>{{ label() }} ({{ age() }})</p>`,
})
export class User {
// Optional input with default value
readonly name = input('Guest');
// Required input
readonly age = input.required<number>();
// Inputs are reactive signals
protected readonly label = computed(() => `Name: ${this.name()}`);
}
```
### Usage in Template
```html
<app-user [name]="userName" [age]="25" />
```
## Configuration Options
The `input` function accepts a config object:
- **Alias**: Change the property name used in templates.
- **Transform**: Modify the value before it reaches the component.
```ts
import { input, booleanAttribute } from '@angular/core';
@Component({...})
export class CustomButton {
// Alias example
readonly label = input('', { alias: 'btnLabel' });
// Transform example using built-in helper
readonly disabled = input(false, { transform: booleanAttribute });
}
```
## Model Inputs (Two-Way Binding)
Use `model()` to create an input that supports two-way data binding.
```ts
@Component({
selector: 'custom-counter',
template: `<button (click)="increment()">+</button>`,
})
export class CustomCounter {
readonly value = model(0);
increment() {
this.value.update((v) => v + 1);
}
}
```
### Usage
```html
<!-- Two-way binding with a signal -->
<custom-counter [(value)]="mySignal" />
<!-- Two-way binding with a plain property -->
<custom-counter [(value)]="myProperty" />
```
## Decorator-based Inputs (@Input)
The legacy API remains supported but is not recommended for new code.
```ts
import { Component, Input } from '@angular/core';
@Component({...})
export class Legacy {
@Input({ required: true }) value = 0;
@Input({ transform: trimString }) label = '';
}
```
## Best Practices
- **Prefer Signals**: Use `input()` instead of `@Input()` for better reactivity and type safety.
- **Required Inputs**: Use `input.required()` for mandatory data to get build-time errors.
- **Pure Transforms**: Ensure input transform functions are pure and statically analyzable.
- **Avoid Collisions**: Do not use input names that collide with standard DOM properties (e.g., `id`, `title`).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| 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: 196k | Updated | Claude CodeCodex | Verified | Install |