# ng2 Dynamic Forms
[](https://badge.fury.io/js/%40ng2-dynamic-forms%2Fcore)
[](https://travis-ci.org/udos86/ng2-dynamic-forms)
[](https://coveralls.io/github/udos86/ng2-dynamic-forms)
ng2 Dynamic Forms is a **rapid form development library** based on the official Angular 2
[**dynamic forms cookbook**](https://angular.io/docs/ts/latest/cookbook/dynamic-form.html).
It simplifies the time-consuming work of implementing reactive Angular 2 forms by building
upon a layer of maintainable form control models to **fully automate form UI creation**.
Therefore it provides a set of **dynamic UI components** with out of the box support for
**[Bootstrap](http://getbootstrap.com)**, **[Foundation](http://foundation.zurb.com/)**, **[Material 2](https://github.com/angular/material2)** and [more](#ui-modules-and-components).
See what's possible by exploring the [**live demo**](http://ng2-dynamic-forms.udos86.de/example/index.aot.html)
and the [**API documentation**](http://ng2-dynamic-forms.udos86.de/docs/)!
## Table of Contents
- [Getting Started](#getting-started)
- [Running the Example](#running-the-example)
- [Basic Usage](#basic-usage)
- [UI Modules and Components](#ui-modules-and-components)
- [Model Bindings and Control References](#model-bindings-and-control-references)
- [Form Groups](#form-groups)
- [Form Arrays](#form-arrays)
- [Form Layouts](#form-layouts)
- [Custom Templates](#custom-templates)
- [Custom Validators](#custom-validators)
- [Validation Messaging](#validation-messaging)
- [JSON Export and Import](#json-export-and-import)
- [Disabling and Enabling Form Controls](#disabling-and-enabling-form-controls)
- [Related Form Controls](#related-form-controls)
- [Autocomplete](#autocomplete)
- [A Word to the Community](#a-word-to-the-community)
- [Appendix](#appendix)
## Getting Started
**1. Install the core package**:
```
npm install @ng2-dynamic-forms/core --save
```
**2. Choose your UI library** (e.g. [**Bootstrap**](http://getbootstrap.com)) and **install the appropriate package**:
```
npm install @ng2-dynamic-forms/ui-bootstrap --save
```
**3.** When using **SystemJS**, update your configuration to **import the corresponding UMD bundles**:
```ts
System.config({
paths: {
"npm:": "node_modules/"
},
map: {
// ...all the rest (Angular 2, RxJS, etc.)
"@ng2-dynamic-forms/core": "npm:@ng2-dynamic-forms/core/bundles/core.umd.js",
"@ng2-dynamic-forms/ui-bootstrap": "npm:@ng2-dynamic-forms/ui-bootstrap/bundles/ui-bootstrap.umd.js",
}
});
```
## Running the Example
**1. Clone the Git repository**:
```
git clone https://github.com/udos86/ng2-dynamic-forms.git
```
**2. Install the npm dependencies**:
```
npm install
```
**3. Transpile the TypeScript files**:
```
npm run tsc
```
**4. Run the sample application**:
```
npm start
```
## Basic Usage
**1. Import the ng2 Dynamic Forms core** `NgModule` **and a corresponding UI** `NgModule`:
```ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { ReactiveFormsModule } from "@angular/forms";
import { DynamicFormsCoreModule } from "@ng2-dynamic-forms/core";
import { DynamicFormsBootstrapUIModule } from "@ng2-dynamic-forms/ui-bootstrap";
// ..all remaining component and routing imports
@NgModule({
imports: [
DynamicFormsCoreModule.forRoot(),
DynamicFormsBootstrapUIModule,
BrowserModule,
ReactiveFormsModule
// ...all remaining imports
],
declarations: [AppComponent, MyDynamicFormComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
```
**2. Define your dynamic form model**:
```ts
import {
DynamicFormControlModel,
DynamicCheckboxModel,
DynamicInputModel,
DynamicRadioGroupModel
} from "@ng2-dynamic-forms/core";
export const MY_DYNAMIC_FORM_MODEL: DynamicFormControlModel[] = [
new DynamicInputModel({
id: "exampleInput",
label: "Example Input",
maxLength: 42,
placeholder: "example input"
}),
new DynamicRadioGroupModel