Angular 17/CdkEditor

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

在 Angular 17 中,我无法将 CKeditor 集成到项目中。在我想使用的组件中:

"message": "组件'CKEditorComponent'出现在'imports'中,但不是独立的,不能直接导入。它必须通过NgModule导入。"

它给出了这个错误,但我无法解决它。你能帮我吗?

我按顺序导入了所有 ts 文件,但最终无法在屏幕上显示编辑器。

我使用了以下但失败了:

<ckeditor [(ngModel)]="model.description" name="description" id="description"></ckeditor>
angular ckeditor5 ng-modules
1个回答
1
投票

错误消息表明您正在尝试导入

CKEditorComponent
,但它不是独立的(Angular 15 中的新功能)。它是模块的一部分,因此您需要导入该模块。

如果您将其导入到独立组件中:

import { Component } from '@angular/core';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';

@Component({
  selector: 'app-foo',
  standalone: true,
  imports: [CKEditorModule],
  template: '<ckeditor [(ngModel)]="model.description" name="description" id="description" />',
})
export class FooComponent {}

或者如果您将其导入到模块中:

import { NgModule } from '@angular/core';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { FooComponent } from './foo/foo.component';

@NgModule({
  imports: [CKEditorModule],
  declarations: [FooComponent]
})
export class FooModule {}

有关更多信息,请参阅文档(特别是快速入门)。

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