You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proper integration of forms in Angular 4 applications using ngrx.
4
6
5
7
Disclaimer: This library is not affiliated with the official ngrx library. I have created it mainly for my own use in one of my projects, but I thought others could profit as well.
6
8
7
-
Please note that this library is still very much work-in-progress and therefore there are many changes still being done. The library is also not yet available via npm. If you want to beta test it you can download the `ngrx-forms-[version].tgz` file from the example app and use that to install the library to your project via:
9
+
There is an [example app](https://ngrx-forms-example-app.herokuapp.com/) that showcases most of the functionality of this library.
10
+
11
+
### Content
12
+
[1 Installation](#1)
13
+
[2 Design Principles](#2)
14
+
[3 User Guide](#3)
15
+
[4 Open Points](#4)
16
+
[5 Contributing](#5)
8
17
18
+
## <aname="1"></a>1 Installation
9
19
```Shell
10
-
npm install [path]ngrx-forms-[version].tgz --save
20
+
npm install ngrx-forms --save
21
+
```
22
+
23
+
This library depends on versions `^4.0.0` of `@angular/core`, `@angular/forms`, and `@ngrx/store`, and version `^5.0.0` of `rxjs`.
24
+
25
+
## <aname="2"></a>2 Design Principles
26
+
This library is written to be as functional and as pure as possible. Most of the heavy lifting is done in pure reducer functions while the directives are only a thin layer to connect the form states to the DOM.
27
+
28
+
This library also tries to be as independent as possible from other libraries/modules. While there is of course a dependency on ngrx the touching points are small and it should be possible to adapt this library to any other redux library without too much effort. There is also a peer dependency on `@angular/forms` from which we re-use the `ControlValueAccessor` concept to allow easier integration with other libraries that provide custom form controls.
29
+
30
+
Conceptually this library borrows heavily from `@angular/forms`, specifically the concepts of form controls and form groups. Groups are simply a collection of named form controls. The state of a group is determined almost fully by its child controls (with the exception of errors which a group can have by itself).
31
+
32
+
## <aname="3"></a>3 User Guide
33
+
34
+
### Getting Started
35
+
36
+
Import the module:
37
+
38
+
```typescript
39
+
import { NgrxFormsModule } from'ngrx-forms';
40
+
41
+
@NgModule({
42
+
declarations: [
43
+
AppComponent,
44
+
...,
45
+
],
46
+
imports: [
47
+
...,
48
+
NgrxFormsModule,
49
+
StoreModule.forRoot(reducers),
50
+
...,
51
+
],
52
+
providers: [],
53
+
bootstrap: [AppComponent]
54
+
})
55
+
exportclassAppModule { }
11
56
```
12
57
13
-
You can see the [example app](https://ngrx-forms-example-app.herokuapp.com/) online.
58
+
Add a group state somewhere in your state tree via `createFormGroupState` and call the `formGroupReducer` inside your reducer:
0 commit comments