项目作者: franzeal

项目描述 :
ngx-formly-designer is an Angular module that adds Components to design forms for Ngx Formly.
高级语言: TypeScript
项目地址: git://github.com/franzeal/ngx-formly-designer.git
创建时间: 2017-06-09T03:33:32Z
项目社区:https://github.com/franzeal/ngx-formly-designer

开源协议:MIT License

下载


ngx-formly-designer

A formly form to design Ngx Formly forms.

The current version is basic and intended for use with bootstrap. Feel welcome to issue feature requests or submit PRs.

Quick Start

Follow these steps to get started with Ngx Formly Designer. Also check out the demo for an example.

1. Install the ngx-formly-designer package:

  1. npm install ngx-formly-designer --save

2. Define the designer config:

  1. import {DesignerConfigOption} from 'ngx-formly-designer';
  2. export const designerConfig: DesignerConfigOption = {
  3. types: [
  4. {
  5. name: 'checkbox',
  6. fields: [
  7. {
  8. key: 'templateOptions.label',
  9. type: 'input',
  10. templateOptions: {
  11. label: 'label'
  12. }
  13. },
  14. {
  15. key: 'defaultValue',
  16. type: 'checkbox',
  17. templateOptions: {
  18. label: 'default value'
  19. }
  20. }
  21. ]
  22. },
  23. ...
  24. ],
  25. wrappers: [
  26. {
  27. name: 'expander',
  28. fields: [
  29. {
  30. key: 'templateOptions.label',
  31. type: 'input',
  32. templateOptions: {
  33. label: 'label'
  34. }
  35. },
  36. {
  37. key: 'templateOptions.expanded',
  38. type: 'checkbox',
  39. templateOptions: {
  40. label: 'expanded'
  41. },
  42. defaultValue: true
  43. }
  44. ]
  45. },
  46. ...
  47. ]
  48. };

3. Import the FormlyDesignerModule:

  1. import {NgModule} from '@angular/core';
  2. import {ReactiveFormsModule} from '@angular/forms';
  3. import {FormlyModule} from '@ngx-formly/core';
  4. import {FormlyBootstrapModule} from '@ngx-formly/bootstrap';
  5. import {designerConfig} from './designer-config';
  6. @NgModule({
  7. imports: [
  8. ...,
  9. ReactiveFormsModule,
  10. FormlyModule.forRoot(),
  11. FormlyBootstrapModule,
  12. FormlyDesignerModule.forRoot(designerConfig)
  13. ],
  14. })
  15. export class AppModule {}

4. Use the formly-designer within your component:

  1. import {Component} from '@angular/core';
  2. import {FormlyFieldConfig} from '@ngx-formly/core';
  3. @Component({
  4. selector: 'app',
  5. template: `
  6. <formly-designer [(fields)]="fields">
  7. </formly-designer>
  8. `,
  9. })
  10. export class AppComponent {
  11. fields: FormlyFieldConfig[] = [];
  12. }