Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

ng-dynamic-forms

> 前端框架
Open source

Rapid form development library for Angular

1.3K stars0 likes2 views
WebsiteGitHub

About

Rapid form development library for Angular

NG Dynamic Forms


NG Dynamic Forms is a rapid form development library based on the official Angular dynamic forms guide.

It fully automates form UI creation by introducing a set of maintainable form control models and dynamic form control components

Out of the box support is provided for all popular UI libraries including Material, ngx-bootstrap, NG Bootstrap, Foundation, Ionic and PrimeNG.

Explore the live sample and the API documentation!

Table of Contents

  • Getting Started
  • Running the Sample
  • Basic Usage
  • UI Modules
  • Form Groups
  • Form Arrays
  • Form Layouts
  • Form Control Configuration
  • Form Control Events
  • Updating Form Controls
  • Custom Templates
  • Custom Validators
  • Custom Form Controls
  • Validation Messaging
  • Related Form Controls
  • JSON Export & Import
  • JSON Form Models
  • Text Masks
  • Autocompletion
  • FAQ
  • Appendix

Getting Started

1. Install the core package:

bash
npm i @ng-dynamic-forms/core -S

2. Install a UI package and its peer dependencies:

bash
npm i @ng-dynamic-forms/ui-material -S

Running the Sample

1. Clone the Git repository:

bash
git clone https://github.com/udos86/ng-dynamic-forms.git
cd ng-dynamic-forms

2. Install the dependencies:

bash
npm i

3. Build the library:

bash
npm run build:lib

4. Run the application:

ng serve

Basic Usage

1. Import the UI module:

typescript
import { DynamicFormsMaterialUIModule } from "@ng-dynamic-forms/ui-material";

@NgModule({
    imports: [
        ReactiveFormsModule,
        DynamicFormsMaterialUIModule
    ]
})

export class AppModule {}

2. Define your form model:

…

3. Create a FormGroup via DynamicFormService:

typescript
import { MY_FORM_MODEL } from "./my-dynamic-form.model";
import { DynamicFormModel, DynamicFormService } from "@ng-dynamic-forms/core";

export class MyDynamicFormComponent {
    formModel: DynamicFormModel = MY_FORM_MODEL;
    formGroup = this.formService.createFormGroup(this.formModel);

    constructor(private formService: DynamicFormService) {}
}

4. Add a DynamicFormComponent to your template and bind its [group] and [model] property:

xml

    
                            

UI Modules

NG Dynamic Forms is built to provide solid yet unobtrusive support for a variety of common UI libraries:

  • Basic
  • Foundation
  • Ionic
  • Material
  • NG Bootstrap
  • ngx-bootstrap
  • PrimeNG

You can instantly plug in your favorite form controls by installing the appropriate package and its peer dependencies:

bash
npm i @ng-dynamic-forms/ui- -S

Now just import the UI module:

typescript
@NgModule({
    imports: [
        ReactiveFormsModule,
        DynamicFormsMaterialUIModule
    ]
})

export class AppModule {}

For creating the form markup all UI modules come with a DynamicFormComponent that can easily be added to your component template:

xml

    
                               

Alternatively you can directly make use of a specific DynamicFormControlComponent to gain more control over rendering:

xml

    

Due to technical restrictions or external dependencies still being in development the support of major form controls varies among UI packages. See the following compatibility table:

| | ui-basic | ui-ngx-bootstrap | ui-foundation | ui-ionic | ui-material | ui-ng-bootstrap | ui-primeng | |---------------- |:--------: |:----------------: |:-------------: |:--------: |:-----------: |:---------------: |:----------: | | Checkbox | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | Checkbox Group | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | Colorpicker | **** | ✗ | **** | **** | **** | **** | ✓ | | Datepicker | * | ✓ | * | ✓ | * | ✓ | ✓ | | Editor | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ | | File Upload | ** | ** | ** | ✗ | ** | ** | ** | | Input | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | Radio Group | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | Rating | ✗ | ✓ | ✗ | ✗ | ✗ | ✗ | ✓ | | Select | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | Slider | *** | *** | *** | ✓ | ✓ | *** | ✓ | | Switch | ✗ | ✗ | ✓ | ✓ | ✓ | ✗ | ✓ | | Textarea | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | Timepicker | * | ✓ | * | ✓ | * | ✓ | ✓ |

*) datetime controls can be achieved using a DynamicInputModel with inputType: "date" or inputType: "time"

**) file upload controls can be achieved using a DynamicInputModel with inputType: "file"

***) slider controls can be achieved using a DynamicInputModel with inputType: "range"

****) color picker controls can be achieved using a DynamicInputModel with inputType: "color"

Form Groups

In order to improve clarity it's often considered good practice to group forms into several logical fieldset sections.

Thus NG Dynamic Forms supports nesting of form groups out of the box!

1. Declare a DynamicFormGroupModel within your form model and add it's models to the group array:

…

2. Create a FormGroup and add a DynamicFormComponent:

typescript
formGroup = this.formService.createFormGroup(this.formModel);
xml

    
                            

3. To manipulate an existing DynamicFormGroupModel you can simply use DynamicFormService:

  • addFormGroupControl(...)
  • insertFormGroupControl(...)
  • moveFormGroupControl(...)
  • removeFormGroupControl(...)

Form Arrays

Sometimes forms need to allow the user to dynamically add multiple items of the same kind to it, e.g. addresses, products and so on.

Particularly for this reason Angular provides so called Form Arrays.

Fortunately, NG Dynamic Forms is capable of managing such nested form structures!

1. Add a DynamicFormArrayModel to your form model:

typescript
export const MY_FORM_MODEL: DynamicFormModel = [

    new DynamicFormArrayModel({
        id: "myFormArray"
    })
];

2. Add the groupFactory property to the DynamicFormArrayModel and assign a function to it which returns the structure of a single form array item:

typescript
new DynamicFormArrayModel({
    id: "myFormArray",
    initialCount: 5,
    groupFactory: () => {
        return [
            new DynamicInputModel({
                id: "myInput",
                label: "My Input"
            })
        ];
    }
})

3. Create a FormGroup via DynamicFormService and bind it to your component template:

typescript
this.formGroup = this.formService.createFormGroup(this.formModel);
xml

    

    Add item
    Remove all items

4. You can now easily modify your form array with DynamicFormService:

typescript
ngOnInit() {
    this.formArrayModel = this.formService.findModelById("myFormArray", this.formModel);
    this.formArrayControl = this.formService.findControlByModel(this.formArrayModel, this.formGroup); 
}

addItem() {
    this.formService.addFormArrayGroup(this.formArrayControl, this.formArrayModel);
    this.formService.detectChanges();
}

clear() {
    this.formService.clearFormArray(this.formArrayControl, this.formArrayModel);
    this.formService.detectChanges();
}

Never forget to trigger change detection via detectChanges when updating a form at runtime!

Alright, works like a charm!

But what if we want to append an additional remove `` for each array group?

Particularly for this case you can add a `` and declare some custom content that is rendered equally for all form array groups:

xml

    
    
        

            Label

        
                                
    

       

Whenever a `` is applied to a DynamicFormArrayModel, NgTemplateOutletContext is internally bound to the associated DynamicFormArrayGroupModel.

That means you can access the group object and it's properties by either declaring a local default template variable or individual local template variables.

see chapter on Custom Templates

xml

    
    
        

            Remove Item
            Add Item

        
                                
    

       

This is extremely useful when you'd like to implement a remove or insert function:

typescript
removeItem(context: DynamicFormArrayModel, index: number) {
    this.formService.removeFormArrayGroup(index, this.formArrayControl, context);
    this.formService.detectChanges();
}

insertItem(context: DynamicFormArrayModel, index: number) {
    this.formService.insertFormArrayGroup(index, this.formArrayControl, context);
    this.formService.detectChanges();
}

Using DynamicFormService again, you can even change the order of the groups in a form array dynamically:

typescript
this.formService.moveFormArrayGroup(index, -1, this.formArrayControl, context);
this.formService.detectChanges();

Form Layouts

When using a NG Dynamic Forms UI package, e.g. ui-bootstrap, all essential form classes of the underlying CSS library (like form-group or form-control) are automatically put in place for you in t

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptangularbootstrapdynamic-formsforms

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架