想要在Angular 2中加入CKeditor

时间:2017-11-15 12:19:59

标签: angular

我正在使用ng2-admin主题。我在 src / app / pages 文件夹结构中创建了两个文件夹Landingpage1和LandingPage2。

现在我在两个单独的文件夹中创建了两个独立的模块:

1。 landingPage1.module.ts

  @NgModule({
    imports: [
        NgaModule,
        CommonModule,
        FormsModule,  
        CKEditorModule,
        routing
    ],
    declarations: [
        LandingPage1,
        Ckeditor,
    ]
})

2。 landingPage2.module.ts

  @NgModule({
    imports:[
        ReactiveFormsModule,
        FormsModule,
        NgaModule,
        CommonModule,
        CKEditorModule,
        routing
    ],
    declarations:[
         LandingPage2,
         Ckeditor,
    ]
})

当我在两个组件文件中使用Ckeditor时,我收到以下错误:

错误:类型Ckeditor是2个模块声明的一部分:LandingPage1Module和LandingPage2Module!请考虑将Ckeditor移动到更高的模块,该模块导入LandingPage1Module和LandingPage2Module。您还可以创建一个新的NgModule,它导出并包含Ckeditor,然后在LandingPage1Module和LandingPage2Module中导入NgModule。

我在app.module.ts文件中导入了Ckeditor但是没有用。

1 个答案:

答案 0 :(得分:1)

Ckeditordeclarations中的landingPage1.module.ts移除landingPage2.module.ts

只需将其保存在导入这两个模块的位置,如果app.module.ts然后添加。

正确的解决方法是创建名为commonModule

EditorCommonModule
@NgModule({
    imports: [
        CKEditorModule
    ],
    exports: [
        CKEditorModule
    ],
    declarations: [],
    providers: [],
})
export class EditorCommonModule { }

然后只需在需要ckEditor的地方导入EditorCommonModule

从每个地方删除CKEditorModuleCkeditor