嵌入 ngx-monaco-editor 时没有 InjectionToken 提供程序

Dav*_*ero 5 angularjs typescript monaco-editor angular ngx-monaco-editor

我正在尝试使用本指南https://github.com/atularen/ngx-monaco-editor#readme将 Monaco Editor 嵌入到我正在开发的 Web 应用程序中。我尝试添加ngx-monaco-editor标签,但 Angular 给了我这个错误。关于如何解决这个问题有什么想法吗?

\n
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]: \n  NullInjectorError: No provider for InjectionToken NGX_MONACO_EDITOR_CONFIG!\nNullInjectorError: R3InjectorError(EditorModule)[InjectionToken NGX_MONACO_EDITOR_CONFIG -> InjectionToken NGX_MONACO_EDITOR_CONFIG -> InjectionToken NGX_MONACO_EDITOR_CONFIG -> InjectionToken NGX_MONACO_EDITOR_CONFIG]: \n  NullInjectorError: No provider for InjectionToken NGX_MONACO_EDITOR_CONFIG!\n    at NullInjector.get (core.js:915)\n    at R3Injector.get (core.js:11082)\n    at R3Injector.get (core.js:11082)\n    at R3Injector.get (core.js:11082)\n    at NgModuleRef$1.get (core.js:24199)\n    at R3Injector.get (core.js:11082)\n    at NgModuleRef$1.get (core.js:24199)\n    at Object.get (core.js:22102)\n    at getOrCreateInjectable (core.js:3921)\n    at Module.\xc9\xb5\xc9\xb5directiveInject (core.js:13753)\n    at resolvePromise (zone-evergreen.js:798)\n    at resolvePromise (zone-evergreen.js:750)\n    at zone-evergreen.js:860\n    at ZoneDelegate.invokeTask (zone-evergreen.js:399)\n    at Object.onInvokeTask (core.js:27425)\n    at ZoneDelegate.invokeTask (zone-evergreen.js:398)\n    at Zone.runTask (zone-evergreen.js:167)\n    at drainMicroTaskQueue (zone-evergreen.js:569)\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的组件.ts

\n
import {Component, OnInit} from \'@angular/core\';\n\n\n\n@Component({\n  selector: \'app-text-editor\',\n  templateUrl: \'./text-editor.component.html\',\n  styleUrls: [\'./text-editor.component.scss\']\n})\nexport class TextEditorComponent implements OnInit {\n\n  editorOptions = {theme: \'vs-dark\', language: \'javascript\'};\n  code: string= \'function x() {\\nconsole.log("Hello world!");\\n}\';\n\n  constructor() {\n  }\n\n  ngOnInit() {\n  }\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

我已经通过安装 v9.0.0 解决了 glob 目录问题,但这个错误确实让我陷入了相当长的一段时间。

\n

编辑通过将 .forRoot 添加到 AppModule 导入来解决。我的错!我以为我已经添加了

\n

Raz*_*nen 4

请确保MonacoEditorModule.forRoot()在您的 AppModule 中。