嵌入 ngx-monaco-editor 时没有 InjectionToken 的提供者

问题描述 投票:0回答:1

我正在尝试使用本指南将 Monaco Editor 嵌入到我正在开发的 Web 应用程序中 https://github.com/atularen/ngx-monaco-editor#readme。我尝试添加

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 目录问题,但这个错误确实让我卡住了一段时间。

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

angularjs angular typescript monaco-editor ngx-monaco-editor
1个回答
4
投票

请确保

MonacoEditorModule.forRoot()
在您的 AppModule 中。

© www.soinside.com 2019 - 2024. All rights reserved.