Radio

Radio.

Examples

Basic Usage

Simplest of usage.

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

@Component({
  selector: 'form-radio-simple',
  template: ` <sf [schema]="schema" (formSubmit)="submit($event)"></sf> `,
})
export class FormRadioSimpleComponent {
  schema: SFSchema = {
    properties: {
      btn: {
        type: 'string',
        title: 'Button',
        enum: ['A', 'B', 'C'],
        ui: {
          widget: 'radio',
          styleType: 'button',
          buttonStyle: 'solid',
        } as SFRadioWidgetSchema,
        default: 'A',
      },
      // 异步数据
      async: {
        type: 'string',
        title: 'Async',
        ui: {
          widget: 'radio',
          asyncData: () =>
            of([
              { label: '男', value: 'M' },
              { label: '女', value: 'F' },
              { label: '未知', value: 'N' },
            ]).pipe(delay(100)),
          change: console.log,
        } as SFRadioWidgetSchema,
        default: 'N',
      },
    },
  };

  constructor(private msg: NzMessageService) {}

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

API

schema

PropertyDescriptionTypeDefault
[readOnly]Whether to disable the stateboolean-
[enum]Render radio groupSFSchemaEnumType[]-

ui

PropertyDescriptionTypeDefault
[asyncData]Async data source() => Observable<SFSchemaEnumType[]>-
[size]Size of the nz-radiostring-
[styleType]Style of the nz-radiodefault, buttondefault
[change]Changed event(res: SFValue) => void-
[buttonStyle]style type of radio button'outline'|'solid''outline'