嵌入 ngx-monaco-editor 时没有 InjectionToken 提供者
No Provider for InjectionToken in embedding ngx-monaco-editor
我正在尝试使用本指南将 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.get (core.js:24199)
at R3Injector.get (core.js:11082)
at NgModuleRef.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 Import 解决。我的错!我以为我已经添加了
请确保 MonacoEditorModule.forRoot()
在您的 AppModule 中。
我正在尝试使用本指南将 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.get (core.js:24199)
at R3Injector.get (core.js:11082)
at NgModuleRef.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 Import 解决。我的错!我以为我已经添加了
请确保 MonacoEditorModule.forRoot()
在您的 AppModule 中。