@jaspero/ng2-form-builder
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

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());
    }
}

Dependents (0)

Package Sidebar

Install

npm i @jaspero/ng2-form-builder

Weekly Downloads

11

Version

0.0.9

License

MIT

Last publish

Collaborators

  • flauc1