Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    @jaspero/ng2-form-builderpublic

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

    install

    npm i @jaspero/ng2-form-builder

    Downloadsweekly downloads

    9

    version

    0.0.9

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar