Angular Forms
ASecurityUse Angular Reactive Forms with an explicitly typed `FormGroup` and non-nullable controls. `validators.ts`: ```ts import { AbstractControl, ValidationErrors, ValidatorFn, } from '@angular/forms'; export const blockedEmailValidator: ValidatorFn = ( control: AbstractControl, ): ValidationErrors | null => { const email = String(control.value).toLowerCase(); return email.endsWith('@blocked.example') ? { blockedEmail: true } : null; }; ``` Component: ```ts import { Component, DestroyRef, inject, }...
- 584 stars
- 0 votes
- 0 copies
- 3 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-forms --agent claude-codeAre you the author of Angular Forms?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-forms-agent-skills-standard)Use Angular Reactive Forms with an explicitly typed `FormGroup` and non-nullable controls.
`validators.ts`:
```ts
import {
AbstractControl,
ValidationErrors,
ValidatorFn,
} from '@angular/forms';
export const blockedEmailValidator: ValidatorFn = (
control: AbstractControl,
): ValidationErrors | null => {
const email = String(control.value).toLowerCase();
return email.endsWith('@blocked.example')
? { blockedEmail: true }
: null;
};
```
Component:
```ts
import {
Component,
DestroyRef,
inject,
} from '@angular/core';
import {
FormBuilder,
FormControl,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { blockedEmailValidator } from './validators';
type ProfileFormControls = {
name: FormControl<string>;
email: FormControl<string>;
};
@Component({
selector: 'app-profile-form',
standalone: true,
imports: [ReactiveFormsModule],
template: `
<form [formGroup]="form" (ngSubmit)="submit()">
<input formControlName="name" />
<input formControlName="email" type="email" />
<button type="submit" [disabled]="form.invalid">
Save
</button>
</form>
`,
})
export class ProfileFormComponent {
private readonly fb = inject(FormBuilder);
private readonly destroyRef = inject(DestroyRef);
readonly form: FormGroup<ProfileFormControls> =
this.fb.nonNullable.group({
name: ['', Validators.required],
email: [
'',
[Validators.required, Validators.email, blockedEmailValidator],
],
});
constructor() {
this.form.valueChanges
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((value) => {
// Sync `value` to a store or service here.
});
}
submit(): void {
if (this.form.invalid) {
this.form.markAllAsTouched();
return;
}
const value = this.form.getRawValue();
console.log(value); // { name: string; email: string }
}
}
```
`fb.nonNullable.group(...)` ensures the controls produce non-null string values. For complex inputs, prefer this strictly typed `FormGroup<T>` approach over an untyped `FormGroup` or template-driven forms.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- eval-4.baseline.md
- eval-4.with-skill.md
- eval-5.baseline.md
- eval-5.with-skill.md
- eval-6.baseline.md
- eval-6.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.