Trung Vo
Trung Vo, web expert with 10 years of experience, Google Developer Expert in Angular, fosters web dev communities and speaks globally, based in Singapore.
Frontend Engineer
San Diego Angular Meetup
Hi, My name is Trung 😊
Angular Forms
Reactive Forms is not strongly typed!
Introducing ngneat/reactive-forms
Rewrite the form with typed
Easy migration
Persist form data
Alternative
Summary
Implicit creations by directive
FormsModule
ngModel
ngForm
Explicit creations in component
ReactiveFormsModule
FormGroup
FormControl
FormArray
FormBuilder
(Angular Reactive) Forms with Benefits 😉
✅ Offers (almost) seamless FormControl, FormGroup, FormArray Replacement
✅ Allows Typed Forms!
✅ Provides Reactive Queries
✅ Provides Helpful Methods
✅ Typed and DRY ControlValueAccessor
✅ Typed FormBuilder
✅ Persist the form's state to a storage
import { FormControl, FormGroup, FormArray, FormBuilder } from '@angular/forms';
⬇️ ⬇️ ⬇️
import { FormControl, FormGroup, FormArray, FormBuilder } from '@ngneat/reactive-forms';
ng g @ngneat/reactive-forms:migrate
initForm() {
this.issueForm = this._fb.group<AddIssueDTO>({
type: [IssueType.TASK],
priority: [IssuePriority.MEDIUM],
title: ['', NoWhitespaceValidator()],
description: [''],
reporterId: [''],
userIds: [[]]
});
this.issueForm.persist('addIssue', {}).subscribe();
}
value$ (raw values)
disabled$
enabled$
status$
dirty$
errors$
valueChanges
statusChanges
touched && errors.required
dirty && errors.required
setValue()
patchValue()
hasErrorAndTouched('required')
hasErrorAndDirty('required')
setValue()
patchValue()
disabledWhile()
markAllAsDirty()
and many more...
By Trung Vo