
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
@larscom/ngrx-store-formsync
Advanced tools
Synchronize any reactive form to @ngrx/store (Angular)
Synchronize any reactive form to @ngrx/store (Angular)
@larscom/ngrx-store-formsync
depends on @ngrx/store and Angular.
npm install @larscom/ngrx-store-formsync
StoreFormSyncModule.forRoot()
only once. For additional modules import StoreFormSyncModule
import { NgModule } from '@angular/core'
import { StoreModule } from '@ngrx/store'
import { StoreFormSyncModule } from '@larscom/ngrx-store-formsync'
@NgModule({
imports: [
StoreModule.forRoot(),
StoreFormSyncModule.forRoot() // import StoreFormSyncModule.forRoot()
]
})
export class AppModule {}
storeFormSyncId
attribute to the same element as formGroup
<form [formGroup]="myFormGroup" storeFormSyncId="1">
<div>
<input formControlName="firstName" />
<input formControlName="lastName" />
</div>
<button type="submit">Submit</button>
</form>
Your formGroup will now get synced to the @ngrx/store
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
formGroup | UntypedFormGroup | undefined | yes | The form group which needs to get synced to the store. |
storeFormSyncId | string | number | undefined | yes | The unique ID for the form group. |
syncDisabled | boolean | false | no | Whether the form group value should sync to the store. |
syncOnSubmit | boolean | false | no | Only sync to the store when submitting the form. |
syncRawValue | boolean | false | no | Sync the raw form value to the store (this will include disabled form controls) |
syncValidOnly | boolean | false | no | Only sync to the store when the form status is valid. |
syncInitialValue | boolean | true | no | Whether the form group value should sync to store when the directive is alive. When disabled, syncing will start when the form value changes |
import { Component } from '@angular/core'
import { storeSelectors } from '@larscom/ngrx-store-formsync' // import selectors
import { Store, select } from '@ngrx/store'
@Component({
selector: 'app-component',
template: `
<div>
<h1>My Form Value</h1>
{{ myFormValue$ | async | json }}
</div>
`,
styleUrls: ['app.component.scss']
})
export class AppComponent {
myFormValue$ = this.store.pipe(select(storeSelectors.selectFormValue({ storeFormSyncId: 'myId' })))
constructor(private readonly store: Store) {}
}
import { Component } from '@angular/core';
import { storeActions } from '@larscom/ngrx-store-formsync'; // import actions
import { Store, select } from '@ngrx/store';
@Component({
selector: 'app-component',
templateUrl: 'app.component.html'
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(private readonly store: Store) {}
setForm(): void {
const value = {
firstName: 'Jan',
lastName: 'Jansen'
};
this.store.dispatch(storeActions.setForm({ storeFormSyncId: 'myId', value }));
}
}
import { Component } from '@angular/core';
import { storeActions } from '@larscom/ngrx-store-formsync'; // import actions
import { Store, select } from '@ngrx/store';
@Component({
selector: 'app-component',
templateUrl: 'app.component.html'
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(private readonly store: Store) {}
patchForm(): void {
const value = {
firstName: 'Jan' // lastName can be omitted
//lastName: 'Jansen'
};
this.store.dispatch(storeActions.patchForm({ storeFormSyncId: 'myId', value }));
}
}
import { Component } from '@angular/core';
import { storeActions } from '@larscom/ngrx-store-formsync'; // import actions
import { Store, select } from '@ngrx/store';
@Component({
selector: 'app-component',
templateUrl: 'app.component.html'
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(private readonly store: Store) {}
deleteForm(): void {
this.store.dispatch(storeActions.deleteForm({ storeFormSyncId: 'myId'}));
}
}
import { Component } from '@angular/core';
import { storeActions } from '@larscom/ngrx-store-formsync'; // import actions
import { Store, select } from '@ngrx/store';
@Component({
selector: 'app-component',
templateUrl: 'app.component.html'
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(private readonly store: Store) {}
deleteAll(): void {
this.store.dispatch(storeActions.deleteAll());
}
}
This library works well with @larscom/ngrx-store-storagesync
You can persist the state of your forms to localStorage/sessionStorage
in a few seconds.
import { storeFormSyncKey } from '@larscom/ngrx-store-formsync' // import storeFormSyncKey
export function storageSyncReducer(reducer: ActionReducer<IRootState>): ActionReducer<IRootState> {
const metaReducer = storageSync<IRootState>({
features: [
{
stateKey: storeFormSyncKey // add storeFormSync as feature
}
],
storage: window.localStorage
})
return metaReducer(reducer)
}
Head over to @larscom/ngrx-store-storagesync on how to configure that library.
FAQs
Synchronize any reactive form to @ngrx/store (Angular)
We found that @larscom/ngrx-store-formsync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.