The goal in creating this was to work with the existing Angular form ecosystem, and save you the trouble of learning a new API. Letโs see how it works:
First, install the library:
## Installation
```
npm i @ngneat/forms-manager
```
Then, create a component with a form:
```ts
import { NgFormsManager } from '@ngneat/forms-manager';
@Component({
template: `
`,
})
export class OnboardingComponent {
onboardingForm: FormGroup;
constructor(private formsManager: NgFormsManager, private builder: FormBuilder) {}
ngOnInit() {
this.onboardingForm = this.builder.group({
name: [null, Validators.required],
age: [null, Validators.required],
city: [null, Validators.required],
});
this.formsManager.upsert('onboarding', this.onboardingForm);
}
ngOnDestroy() {
this.formsManager.unsubscribe('onboarding');
}
}
```
As you can see, weโre still working with the existing API in order to create a form in Angular. Weโre injecting the `NgFormsManager` and calling the `upsert` method, giving it the form name and an `AbstractForm`.
From that point on, `NgFormsManager` will track the `form` value changes, and update the store accordingly.
With this setup, youโll have an extensive API to query the store and update the form from anywhere in your application:
## API
- `valueChanges()` - Observe the control's value
```ts
const value$ = formsManager.valueChanges('onboarding');
const nameValue$ = formsManager.valueChangesNetanel Basal ๐ป ๐ ๐ค |
Colum Ferry ๐ป ๐ |
Mehmet Erim ๐ |
David Speirs ๐ป ๐ |
Emmanuel De Saint Steban ๐ป ๐ |
Adrian Riepl ๐ป ๐ |