Simple adapter with bindings between @angular/reactive-forms and @ngrx/store.
You'll need to do three things to add ngrx-store-forms to your existing project:
- Import the module
- Add the meta reducer
- Register the side effects
Import the module using StoreFormsModule.forRoot() within the imports section of your
root module. You also need to add storeFormsMetaReducer meta reducer to the
StoreModule configuration object. As a last step, use the ngrx EffectsModule to register
the StoreFormsEffects side effects.
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
ReactiveFormsModule,
StoreModule.forRoot({...}, {
metaReducers: [storeFormsMetaReducer]
}),
EffectsModule.forRoot([
StoreFormsEffects
]),
StoreFormsModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}@NgModule({
declarations: [FeatureComponent],
imports: [
CommonsModule,
ReactiveFormsModule,
StoreModule.forFeature('coolFeature', {...}, {
metaReducers: [storeFormsMetaReducer]
}),
EffectsModule.forFeature([
StoreFormsEffects
]),
StoreFormsModule.forFeature('coolFeature')
],
providers: [],
bootstrap: [FeatureComponent]
})
export class FeatureModule {
}You can use the rxsfBinding directive to bind your form group to the store.
<form [formGroup]="formGroup"
rxsfBinding="subState.form"
novalidate>
<input formControlName="name">
<input formControlName="userName">
</form>That's it! After this change ngrx-store-forms will dispatch UpdateStoreFormStateAction actions when
your reactive form has changed. A object of type FormGroupState will be written into
your store at the location specified within the rxsfBinding directive.
- Documentation
- Separate example app from library project