【发布时间】:2021-09-29 22:10:54
【问题描述】:
我目前正在尝试在我的 Angular 12 项目中更改 ngx-monaco-editor 元素的背景颜色,但到目前为止我没有尝试过任何方法。有没有办法可以用我当前的设置轻松地做到这一点,还是我需要用另一种方法重做?这是我目前正在尝试做的,但编辑器最终看起来像“vs”主题。我的代码片段:
component1.html
<div class="data" id="d2">
<ngx-monaco-editor id="xmlDisplayer" style="height: 100%;" [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor>
</div>
component1.ts
import { Component, OnInit } from '@angular/core';
import { DataMapService } from '../data-map.service';
import { MonacoEditorLoaderService } from '@materia-ui/ngx-monaco-editor';
import { saveAs } from "file-saver";
import * as d3 from 'd3';
export class component1 implements OnInit {
constructor(private dataMapService: DataMapService, private monacoLoaderService: MonacoEditorLoaderService) {
this.monacoLoaderService.isMonacoLoaded$.pipe(
).subscribe(() => {
(window as any).monaco.editor.defineTheme('myCustomTheme', {
base: 'vs-dark', // can also be vs-dark or hc-black
colors: {
"editor.background": '#AA4A44', // code background
'editorCursor.foreground': '#002438', // corsour color
'editor.lineHighlightBackground': '#9B9B9B', // line highlight colour
'editorLineNumber.foreground': '#666666', // line number colour
'editor.selectionBackground': '#666666', // code selection background
'editor.inactiveSelectionBackground': '#7e890b'
}
});
});
}
ngOnInit(): void {
}
//options and text for the xml display
editorOptions = {theme: 'myCustomTheme', language: 'xml'};
code = "xml stuff goes here";
app.module.ts
import { MonacoEditorModule } from 'ngx-monaco-editor';
//Other component imports and misc
@NgModule({
declarations: [
AppComponent,
//Component declarations
],
imports: []
//Other imports
MonacoEditorModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
我遇到的另一个问题是,当我尝试在其他地方执行“monaco.editor.defineTheme(...)”时,我在 monaco 命名空间中遇到错误。我们将不胜感激。
【问题讨论】:
标签: angular typescript monaco-editor