A decorator implementation for Angular 2 Reactive Forms
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
examples/webpack
src
tests
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
index.ts
karma.conf.js
ng2-form-builder.ts
package.json
tsconfig.json
tslint.json
webpack.config.js

README.md

Build Status NPM Version

NG2 Form-Builder

This library provides a faster and cleaner way to use Angular 2 Reactive Forms through typescript decorators.

Setup

Import FormBuilderModule in your @NgModule and you're good to go:

@NgModule({
    imports: [
        FormBuilderModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {}

How to use

To use this library simply create a class and add @JasperoBuilder.dec() decorators to each property:

export class User {
    @JasperoBuilder.dec({initial: ''})
    username: string;
    @JasperoBuilder.dec({initial: ''})
    password: string;
}

The dec() method accepts the same arguments as new FormControl() does and creates the FormControl in the background.

Then in your component create the FormGroup like this:

export class AppComponent {
    constructor(private _jb: JasperoBuilder) {}
    
    userForm: any;

    ngOnInit() {
        // You can also instantiate the class with values
        this.useForm = this._jb.createForm(new User());
    }
}