【问题标题】:Want to Include CKeditor in Angular 2想要在 Angular 2 中包含 CKeditor
【发布时间】:2018-04-28 16:03:28
【问题描述】:

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

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

1. loginPage1.module.ts

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

2。 loginPage2.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 但不起作用。

【问题讨论】:

    标签: angular


    【解决方案1】:

    declarations 中的landingPage1.module.tslandingPage2.module.ts 中删除Ckeditor

    只要把它放在你要导入这 2 个模块的地方,如果 app.module.ts 然后添加那里。


    对此的正确解决方案是创建一个名为 EditorCommonModulecommonModule

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

    然后将这个 EditorCommonModule 导入到任何需要 ckEditor 的地方。

    从所有位置删除 CKEditorModuleCkeditor

    【讨论】:

    • 是的,我已经从 app.module.ts 文件中删除了 Ckeditor。
    • For One Landing1 页面工作正常,但当我重定向到 Landing page2 时。它给了我错误。
    • 我不会在任何地方添加模块。我只是把代码放在 pages.routing.ts 文件中 ** export const routes: Routes = [ { path: 'reviewForm1', loadChildren: 'app/pages/landingPage1/landingPage1.module#LandingPage1' }, { path: 'reviewForm1 ', loadChildren: 'app/pages/landingPage2/landingPage1.module#LandingPage2' }, ];**
    • @ManeeshRao,请按照我提到的正确解决方案更新您的代码。
    • @ManeeshRao,现在需要您在 plnkr 或 jsfiddle 上的代码进行调试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 2017-03-12
    • 2018-02-12
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    相关资源
    最近更新 更多