标签

进行标记和分类的小标签,注: 只支持 checkable 标签模式。

代码演示

基础样例

最简单的用法。

expand codeexpand code
import { Component } from '@angular/core';
import { SFIcon, SFSchema, SFTagWidgetSchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';
import { of, delay } from 'rxjs';

@Component({
  selector: 'form-tag-simple',
  template: ` <sf [schema]="schema" (formSubmit)="submit($event)"></sf> `,
})
export class FormTagSimpleComponent {
  schema: SFSchema = {
    properties: {
      like: {
        type: 'number',
        title: '兴趣',
        enum: [
          { value: 1, label: '电影' },
          { value: 2, label: '书' },
          { value: 3, label: '旅行' },
        ],
        ui: {
          widget: 'tag',
        } as SFTagWidgetSchema,
        default: [1, 2],
      },
      like1: {
        type: 'number',
        title: '兴趣',
        ui: {
          widget: 'tag',
          asyncData: () =>
            of([
              { value: 1, label: '电影' },
              { value: 2, label: '书' },
              { value: 3, label: '旅行' },
            ]).pipe(delay(10)),
        } as SFTagWidgetSchema,
        default: [1, 2],
      },
      icon: {
        type: 'number',
        title: '兴趣',
        enum: [
          { value: 1, label: 'Twitter', prefixIcon: { type: 'twitter' } as SFIcon },
          { value: 2, label: 'Facebook', suffixIcon: { type: 'facebook' } as SFIcon },
        ],
        ui: {
          widget: 'tag',
        } as SFTagWidgetSchema,
      },
    },
  };

  constructor(private msg: NzMessageService) {}

  submit(value: {}): void {
    this.msg.success(JSON.stringify(value));
  }
}

API

schema 属性

成员说明类型默认值
[enum]数据源SFSchemaEnumType[]-

ui 属性

成员说明类型默认值
[asyncData]异步数据源() => Observable<SFSchemaEnumType[]>-
[mode]设定标签工作的模式'closeable'|'default'|'checkable''checkable'
[onClose]关闭时的回调,在 nzMode="closable" 时可用(e:MouseEvent) => void-
[checkedChange]设置标签的选中状态的回调(status: boolean) => void-