Ueditor Rich Text

Ueditor Rich Text.

Note: third party widget is not registered by default, see details from Customize Widgets.

Installation dependencies

Since the Ueditor relies on a third-party plug-in ngx-ueditor, the dependency should be installed first when using it

yarn add ngx-ueditor

Import module

  • The project built using the latest scaffolding provides a third-party widget registration entry: src/app/shared/json-schema/json-schema.module.ts.

  • UeditorWidget needs to be declared in JsonSchemaModule.

export const SCHEMA_THIRDS_COMPONENTS = [UeditorWidget];

@NgModule({
  declarations: SCHEMA_THIRDS_COMPONENTS,
  imports: [
    SharedModule,
    DelonFormModule.forRoot(),
    UEditorModule.forRoot({
      js: [`./assets/ueditor/ueditor.config.js`, `./assets/ueditor/ueditor.all.min.js`],
      // 默认前端配置项
      options: {
        UEDITOR_HOME_URL: './assets/ueditor/'
      }
    }),
  ],
  exports: SCHEMA_THIRDS_COMPONENTS
})
export class JsonSchemaModule {
}

Widget registration

  • Register the widget to the WidgetRegistry registry

export class JsonSchemaModule {
  constructor(widgetRegistry: WidgetRegistry) {
    widgetRegistry.register(UeditorWidget.KEY, UeditorWidget);
  }
}

Import resources

Roughly the same as Tinymce, Ueditor also needs to import some static resource files to run normally

  • It can be downloaded from Ueditor Release as needed

  • Put the static resource file into a path accessible by config to complete the configuration

Source Code

Source Code

Examples

Basic Usage

Simplest of usage.

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

@Component({
  selector: 'form-ueditor-simple',
  template: `<sf [schema]="schema" (formSubmit)="submit($event)"></sf>`,
})
export class FormUeditorSimpleComponent {
  schema: SFSchema = {
    properties: {
      remark: {
        type: 'string',
        title: '描述',
        ui: {
          widget: 'ueditor',
        },
      },
    },
  };

  constructor(private msg: NzMessageService) {}

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

API

ui

PropertyDescriptionTypeDefault
[config]Configuration options, official websiteobject-
[loading]Initial hint messagestring加载中...
[delay]Lazy initialize UEditor, unit: millisecondnumber300
[change]Callback function when content in editor is changed(html: string) => void-