AGENT SKILL
angular-forms
Standards for Typed Reactive Forms and Validators. Use when implementing typed reactive forms, custom validators, or form control patterns in Angular. (triggers: FormBuilder, FormGroup, FormControl, Validators, reactive forms, typed forms)
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
01 前言 Front Matter
- name
- angular-forms
- description
- Standards for Typed Reactive Forms and Validators. Use when implementing typed reactive forms, custom validators, or form control patterns in Angular. (triggers: FormBuilder, FormGroup, FormControl, Validators, reactive forms, typed forms)
02 资源文件 5
- 脚本examples/console_logging.py1.0 KB
- 脚本examples/element_discovery.py1.4 KB
- 脚本examples/static_html_automation.py953 B
- 许可证LICENSE.txt11.1 KB
- 脚本scripts/with_server.py3.6 KB
03 SKILL.md 正文
Forms
Priority: P2 (MEDIUM)
Principles
- Reactive Forms: Always use Reactive Forms (FormControl, FormGroup) over Template-Driven Forms for complex inputs. Template-driven forms are only acceptable for very simple, single-field cases. Reactive forms are strictly typed, testable, and compose better with Signal stores.
- Strict Typing: Use strictly typed forms using FormGroup<T> with a typed interface:
FormGroup<{ email: FormControl<string>; password: FormControl<string> }>. Never use untyped FormGroup. - Non-Nullable: Use
fb.nonNullable.group({ email: ['', Validators.email], password: [''] })or nonNullable: true on individualFormControlfor fine-grained control. This ensures form values are always strings — Avoid null in form values by usingfb.nonNullable.group.
Guidelines
- Component Store integration: Sync valueChanges using takeUntilDestroyed() to call store.update().
- Split Logic: Logic for validation should be in custom validator functions (e.g., function passwordStrength(control: AbstractControl): ValidationErrors | null). Extract validation into a separate file — do not put validation logic inside the component class.
Anti-Patterns
- No Template-Driven Forms: Use Reactive Forms for any non-trivial inputs.
- No untyped FormGroup: Always use strictly typed
FormGroup<T>. - No validation in component: Extract validation into standalone validator functions. Inject FormBuilder with fb = inject(FormBuilder).