问题描述
我正在尝试使用本指南 https://github.com/atularen/ngx-monaco-editor#readme 将 Monaco Editor 嵌入到我正在处理的网络应用程序中。我尝试添加 ngx-monaco-editor
标签,Angular 给了我这个错误。有关如何解决此问题的任何想法?
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(EditorModule)[InjectionToken NGX_MONACO_EDITOR_CONfig -> InjectionToken NGX_MONACO_EDITOR_CONfig -> InjectionToken NGX_MONACO_EDITOR_CONfig -> InjectionToken NGX_MONACO_EDITOR_CONfig]:
NullInjectorError: No provider for InjectionToken NGX_MONACO_EDITOR_CONfig!
NullInjectorError: R3InjectorError(EditorModule)[InjectionToken NGX_MONACO_EDITOR_CONfig -> InjectionToken NGX_MONACO_EDITOR_CONfig -> InjectionToken NGX_MONACO_EDITOR_CONfig -> InjectionToken NGX_MONACO_EDITOR_CONfig]:
NullInjectorError: No provider for InjectionToken NGX_MONACO_EDITOR_CONfig!
at NullInjector.get (core.js:915)
at R3Injector.get (core.js:11082)
at R3Injector.get (core.js:11082)
at R3Injector.get (core.js:11082)
at NgModuleRef$1.get (core.js:24199)
at R3Injector.get (core.js:11082)
at NgModuleRef$1.get (core.js:24199)
at Object.get (core.js:22102)
at getorCreateInjectable (core.js:3921)
at Module.ɵɵdirectiveInject (core.js:13753)
at resolvePromise (zone-evergreen.js:798)
at resolvePromise (zone-evergreen.js:750)
at zone-evergreen.js:860
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:27425)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at drainMicroTaskQueue (zone-evergreen.js:569)
这是我的component.ts
import {Component,OnInit} from '@angular/core';
@Component({
selector: 'app-text-editor',templateUrl: './text-editor.component.html',styleUrls: ['./text-editor.component.scss']
})
export class TextEditorComponent implements OnInit {
editorOptions = {theme: 'vs-dark',language: 'javascript'};
code: string= 'function x() {\nconsole.log("Hello World!");\n}';
constructor() {
}
ngOnInit() {
}
}
我已经通过安装 v9.0.0 解决了 glob 目录问题,但是这个错误确实让我卡住了很长时间。
EDIT 通过将 .forRoot 添加到 AppModule 导入来解决。我的错!我以为我已经添加了
解决方法
请确保 MonacoEditorModule.forRoot()
在您的 AppModule 中。