0.0.2 • Published 5 years ago

@poseclop/ng-typed-form v0.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

NgTypedForm

Provides an angular service to generate typed reactive forms.

The interface for typed forms is inspired from this gist

:warning: This module was not tested in depth for production. Use at your own risk and peril.

Installation

  1. Install the Package with npm install @poseclop/ng-typed-form
  2. Import the module in your application (ReactiveFormsModule also required)
    @ngModule({
        ...,
        imports: [
            ...,
            NgTypedFormModule,
            ReactiveFormsModule
        ]
    })

API

NgTypedFormService

Methods
NameReturnDescription
generateTypedFormControl<T>(value: T, config?: IPosConfig)TypedFormGroup<T>Generate a typed FormGroup
generateTypedFormArray<T>(value: T, config?: IPosConfig)TypedFormArray<T>Generate a typed FormArray (type: T[])
generateTypedFormGroup<T>(value: T: config?: PosFormCongif)TypedFormGroup<T>Generate a typed FormGroup
IPosConfig
NameDescription
disabled: booleandisable the control (default: false)
nullDefault: booleannullify the default value (default: false)
validators: Validator | Validator[]set the default validators
PosFormConfig

An object partially matching T with IPosConfig assigned to each value.

Limitations

Currently, the service will generate a FormArray form any array provided as default values. Arrays with varying types are not supported.

This package has not been tested rigorously. Use at you own rish and peril

Todo

  • Allow the user to provide reactive form configuration
  • Manage form arrays with different types
  • Allow FormControls with values of type Array
  • Manage null values
  • Manage interface declaration with partial default value