首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Angular中使用Ace-Editor?

如何在Angular中使用Ace-Editor?
EN

Stack Overflow用户
提问于 2021-10-23 18:43:41
回答 1查看 316关注 0票数 1

我正在使用Angular 12和ACE编辑器开发一个web组件。我一步一步地遵循了教程(下面的链接),但最终得到了奇怪的结果。我最终将编辑器放在了一个灰色的细列中--而且它并没有连接到-in。(https://blog.shhdharmen.me/how-to-setup-ace-editor-in-angular)

你知道为什么会发生这种事吗?

seite.html

代码语言:javascript
复制
<div class="app-ace-editor"
     style="width: 500px;height: 250px;"
     #editor></div>

component.ts

代码语言:javascript
复制
import { Component, ElementRef, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import * as ace from "ace-builds";

@Component({
  selector: 'app-studentfe',
  templateUrl: './studentfe.component.html',
  styleUrls: ['./studentfe.component.css'],
  encapsulation : ViewEncapsulation.ShadowDom
})

export class StudentfeComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }

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

  ngAfterViewInit(): void {
     ace.config.set("fontSize", "14px");
     ace.config.set(
        'basePath',
        "https://ace.c9.io/build/src-noconflict/ace.js"
     );

     const aceEditor = ace.edit(this.editor.nativeElement);
     aceEditor.setTheme("ace/theme/monokai");
     aceEditor.session.setMode("ace/mode/html");
     aceEditor.on("change", () => {
        console.log(aceEditor.getValue());
     });
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-24 14:13:51

这是由于隐藏了全局样式而不让ace看到的。

添加

代码语言:javascript
复制
 aceEditor.renderer.attachToShadowRoot()

为了让编辑器知道它在卷影dom元素中,需要给它添加额外的样式。

此外,basepath不应包含ace.js

代码语言:javascript
复制
ace.config.set('basePath', "https://ace.c9.io/build/src-noconflict/");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69691071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档