开关

开关选择器

代码演示

基础样例

最简单的用法。

expand code expand code
import { Component, inject } from '@angular/core';

import { YelonFormModule, SFSchema } from '@yelon/form';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'form-boolean-simple',
  template: ` <sf [schema]="schema" (formSubmit)="submit($event)" /> `,
  standalone: true,
  imports: [YelonFormModule]
})
export class FormBooleanSimpleComponent {
  private readonly msg = inject(NzMessageService);
  schema: SFSchema = {
    properties: {
      status: {
        type: 'boolean',
        title: '是否启用'
      },
      // 指定内容文本
      enabled: {
        type: 'boolean',
        title: '是否启用',
        ui: {
          checkedChildren: '开',
          unCheckedChildren: '关'
        }
      }
    }
  };

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

API

schema属性

参数说明类型默认值
[readOnly]禁用状态boolean-

ui属性

参数说明类型默认值
[size]大小,等同 nzSizedefault,smalldefault
[checkedChildren]选中时的内容string-
[unCheckedChildren]非选中时的内容string-
[loading]加载中的开关booleanfalse
Loading...