相关疑难解决方法(0)

ACE 编辑器 - 允许在 Angular/TypeScript 中自定义模式和主题

介绍:

我有一个 Angular 应用程序,可以使用 ACE 编辑器 ( https://ace.c9.io/ ) 编写自定义 SQL 语句。尽管有模式和主题SQL,但我想根据我的要求创建自定义模式和自定义主题。


设置:

我遵循了本教程:https://blog.shhdharmen.me/how-to-setup-ace-editor-in-angular

  • ng new ace-app(角度13.3.2)
  • npm install ace-builds(ACE-构建 1.4.14)

component.ts

import * as ace from 'ace-builds';

...

public aceEditor: ace.Ace.Editor;

@ViewChild('editor') private editor!: ElementRef<HTMLElement>;

...

  ngAfterViewInit(): void {
    // I don't understand why we don't set the "basePath" to our installed package
    ace.config.set('basePath', 'https://unpkg.com/ace-builds@1.4.12/src-noconflict');

    this.aceEditor = ace.edit(this.editor.nativeElement);

    if (this.aceEditor) {
      this.aceEditor.setOptions({
        mode: 'ace/mode/sql',
        theme: 'ace/theme/sqlserver',
      });
    }
Run Code Online (Sandbox Code Playgroud)

component.html

<div #editor></div>
Run Code Online (Sandbox Code Playgroud)

结果:

编辑器正在工作,但现在我需要以某种方式添加自定义模式和主题。

带有 sql 语句的 ACE 编辑器框


问题和疑问: …

sql ace-editor typescript angular

7
推荐指数
1
解决办法
1963
查看次数

标签 统计

ace-editor ×1

angular ×1

sql ×1

typescript ×1