npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@freezesoul/nz-formly

v17.0.16

Published

基于ng-zorro-antd UI 扩展的ngx-formly组件库

Downloads

3

Readme

NzFormly

注:切换至16.x版本,原版地址:https://m310851010.github.io/nz-formly

基于ng-zorro-antd UI 扩展的ngx-formly组件库

demo

Alt Text

用法

安装

npm i @ngx-formly/core @freezesoul/nz-formly @freezesoul/nzx-antd

导入模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NzFormlyModule } from '@freezesoul/nz-formly';
import { FormlyModule } from '@ngx-formly/core';

/**
 * ngx-formly的nz组件, 包含常用的表单组件
 */
@NgModule({
  imports: [
    CommonModule,
    // 使用nz-formly所必须的模块
    FormlyModule,
    NzFormlyModule
  ]
})
export class AppModule {}

上面代码导入的是基础模块, 要用里面的组件需要导入对应的模块。

通常我们会创建一个module用来存放nz-formly用到的组件,例如:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NzFormlyModule } from '@freezesoul/nz-formly';
import { FormlyModule } from '@ngx-formly/core';
import { FormlyCommonModule } from '@freezesoul/nz-formly/common';
import { FormlyNzCheckboxModule } from '@freezesoul/nz-formly/checkbox';
import { FormlyNzInputModule } from '@freezesoul/nz-formly/input';
import { FormlyNzDatePickerModule } from '@freezesoul/nz-formly/date-picker';
import { FormlyNzDateRangePickerModule } from '@freezesoul/nz-formly/date-range-picker';
import { FormlyNzRadioModule } from '@freezesoul/nz-formly/radio';
import { FormlyNzGridModule } from '@freezesoul/nz-formly/grid';
import { FormlyNzFormFieldModule } from '@freezesoul/nz-formly/field-wrapper';
import { FormlyNzTextareaModule } from '@freezesoul/nz-formly/textarea';
import { FormlyNzTextValueModule } from '@freezesoul/nz-formly/text-value';
import { FormlyNzSelectModule } from '@freezesoul/nz-formly/select';
import { FormlyNzSwitchModule } from '@freezesoul/nz-formly/switch';

/**
 * ngx-formly的nz组件, 包含常用的表单组件
 */
@NgModule({
  exports: [
    CommonModule,
    FormlyModule,
    NzFormlyModule,
    FormlyCommonModule,
    FormlyNzCheckboxModule,
    FormlyNzInputModule,
    FormlyNzDatePickerModule,
    FormlyNzDateRangePickerModule,
    FormlyNzRadioModule,
    FormlyNzGridModule,
    FormlyNzFormFieldModule,
    FormlyNzTextareaModule,
    FormlyNzTextValueModule,
    FormlyNzSelectModule,
    FormlyNzSwitchModule
    // 其他组件
  ]
})
export class SharedFormlyModule {}

模板的写法

仍然采用 ngx-formly的原生用法,nz-formly扩展了便捷的操作

<form nz-form [formGroup]="form" (ngSubmit)="submit()">
  <formly-form formly-box [model]="model" [fields]="fields" [options]="options" [form]="form">
    <ng-template named="icon-button">
      <button nz-button nzType="primary" nzSearch><i nz-icon nzType="search"></i></button>
    </ng-template>
  </formly-form>
</form>

组件的写法

@Component({
  ...
})
export class AppComponent {
  form = new FormGroup({});
  model = { awesome: [1, 2], switchDemoKey: 'XX', myText2: 'some text' };
  options: FormlyFormOptions = {
    formState: {
      labelNzFlex: '100px',
      controlNzFlex: 'auto'
    }
  };
  fields: NzField[] = [
    {
      key: 'name',
      type: 'input',
      props: {
        label: '名称',
        required: true,
        nzSearch: true,
        nzAddOnAfterName: 'icon-button'
      }
    },
    {
      key: 'awesome',
      type: 'checkbox',
      props: {
        label: '渠道',
        options: [
          { label: '网络', value: 1 },
          { label: '代理商', value: 2 },
          { label: '其他', value: 3 }
        ]
      }
    },
    {
      key: 'radioKey',
      type: 'radio',
      props: {
        label: '单选',
        options: [
          { label: '网络', value: 1 },
          { label: '代理商', value: 2 },
          { label: '其他', value: 3 }
        ]
      }
    },
    {
      key: 'switchDemoKey',
      type: 'switch',
      props: {
        label: '开关',
        nzxCheckedValue: 'XX',
        nzxUnCheckedValue: 'YY'
      }
    },
    {
      key: 'comment',
      type: 'textarea',
      props: {
        label: '评论',
        rows: 2,
        maxLength: 100,
        nzMaxCharacterCount: 100
      }
    },
    {
      key: 'status',
      type: 'select',
      props: {
        label: '状态',
        nzAllowClear: true,
        options: [
          { label: 'AA', value: 'aa' },
          { label: 'BB', value: 'bb' }
        ]
      }
    },
    {
      key: 'myText',
      type: 'text',
      props: {
        label: '文本'
      }
    },
    {
      key: 'myText2',
      type: 'text',
      props: {
        label: '文本2'
      }
    }
  ];

  submit() {
    if (this.form.valid) {
      alert(JSON.stringify(this.model));
    }
  }
}

运行环境

  • ndoejs 14+
  • angular 13.0+
  • ng-zorro-antd 13.0+
  • @ngx-formly/core 6.0+
  • @freezesoul/nzx-antd 13.0+ (angular 14 请安装@freezesoul/nzx-antd 14.0+)

License

The MIT License (see the LICENSE file for the full text)