ng2-easyform
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

ng2-easyform

npm package

一种快速建表单的方法,抽象出字段定义,如字段label、占位、必填、可写、值变换等。根据字段定义生成表单。 项目状态:开发中

使用

npm install ng2-easyform --save

Material Form

引入如下angular module

import { EasyFormCoreModule, EasyFormMdModule } from 'ng2-easyform'

In your component

import { Component, ViewChild } from '@angular/core';
 
import {
    FieldBase,
    MdTextinputField,
    MdTextareaField,
    MdDatepickerField,
    MdSelectField,
    MdFormComponent,
    MdCheckboxField
} from 'ng2-easyform'
 
@Component({
    selector: 'md-form-demo',
    template: `
    <ef-md-form [fields]="fields"></ef-md-form>
    <span>表单值:{{formvalue}}</span>
`,
})
export class MdEasyformComponent {
 
    fields: FieldBase<any>[]
    formvalue: string
 
    @ViewChild(MdFormComponent) form: MdFormComponent
 
    constructor() {
    }
    ngOnInit() {
        this.fields = [
            new MdTextinputField({
                key: "userId",
                label: "用户ID",
                required: true,
                // disabled: true,
                span: 4,
            }),
            new MdTextinputField({
                key: "userName",
                label: "用户名",
                required: true,
                span: 4,
                valueChange: (value) => {
 
                } //值变换
            }),
            new MdDatepickerField({
                key: "bornTime",
                label: "出生日期",
                required: true,
                span: 4,
            }),
            new MdDatepickerField({
                key: "inTime",
                label: "入职日期",
                required: true,
                disabled: true,
                span: 4,
            }),
            new MdCheckboxField({
                key: "enable",
                label: "启用",
                required: true,
                span: 4,
            }),
            new MdSelectField({
                key: "gender",
                label: "性别",
                required: true,
                span: 4,
                dictName: '性别',
                noneOption: false
            }),
            new MdTextareaField({
                key: "userAddress",
                label: "地址",
                required: false,
                span: 10,
            }),
            new MdTextareaField({
                key: "userAddress1",
                label: "地址1",
                required: false,
                span: 8,
            }),
            new MdTextareaField({
                key: "userAddress2",
                label: "地址2",
                required: false,
                span: 12,
            }),
        ]
    }
    ngAfterViewInit() {
        this.form.form.valueChanges.subscribe(value => {
            this.formvalue = JSON.stringify(value)
        })
    }
}

Ant Form

正在整合中

demo

demo

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.6.02latest

Version History

VersionDownloads (Last 7 Days)Published
0.6.02
0.3.142
0.3.130
0.3.121
0.3.110
0.3.100
0.3.91
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.00
0.2.10
0.2.00
0.1.20
0.1.11
0.1.00
0.0.90
0.0.8-beta.112
0.0.8-beta.102
0.0.8-beta.90
0.0.8-beta.80
0.0.8-beta.70
0.0.8-beta.60
0.0.8-beta.50
0.0.8-beta.40
0.0.8-beta.30
0.0.8-beta.20
0.0.8-beta.10
0.0.70
0.0.6-beta.80
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i ng2-easyform

Weekly Downloads

11

Version

0.6.0

License

MIT

Unpacked Size

773 kB

Total Files

46

Last publish

Collaborators

  • liqiao