微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决嵌入 ngx-monaco-editor 时没有 InjectionToken 提供程序

我正在尝试使用本指南 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 中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。