【问题标题】:No Provider for InjectionToken in embedding ngx-monaco-editor嵌入 ngx-monaco-editor 中没有 InjectionToken 提供程序
【发布时间】:2021-01-22 01:22:44
【问题描述】:

我正在尝试使用本指南 https://github.com/atularen/ngx-monaco-editor#readme 将 Monaco Editor 嵌入到我正在开发的 Web 应用程序中。我尝试添加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 Import 来解决。我的错!我以为我已经添加了它

【问题讨论】:

  • 你在 AppModule 中添加了MonacoEditorModule.forRoot() 吗?
  • 哦!我实际上忘记了 add.forRoot()。谢谢!
  • 我已经在我的高级模块中添加了 MonacoEditorModule.forRoot(config),但是在我将它添加到 app.module.ts 之前看到了这个错误。我不必在从头开始的简单应用程序中执行此操作。

标签: angularjs angular typescript monaco-editor ngx-monaco-editor


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-03-26
    • 2018-10-04
    • 2021-09-08
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2018-11-28
    • 1970-01-01
    相关资源
    最近更新 更多