【问题标题】:Angular not a known element error角度不是已知的元素错误
【发布时间】:2018-04-10 16:20:09
【问题描述】:

我现在正在使用 Angular 和 Electron。

我已经通过我的模块文件导入了ngx-quill

@NgModule({
imports: [
    ~~~,
    QuillModule
],
exports: [RouterModule]
})

我从我的主要组件文件中导入了Quill

import { QuillEditorComponent } from 'ngx-quill/src/quill-editor.component';
import Quill from 'quill';

我在我的 html 模板中使用了 quill-editor 组件

<quill-editor></quill-editor>

我得到了一个类似的错误:

'quill-editor' is not a known element:
1. If 'quill-editor' is an Angular component, then verify that it is part of this module.
2. If 'quill-editor' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

【问题讨论】:

  • 您只有AppModule 还是您自己的代码中还有其他模块?
  • import { QuillEditorModule } from 'ngx-quill-editor'; 尝试将其导入您的 main.module 文件中。
  • 谢谢大家。我通过在右侧模块文件中导入QuillModule 解决了这个问题

标签: angular electron quill


【解决方案1】:
@NgModule({
imports: [
    QuillModule
],

需要添加到您实际使用导入模块的组件的模块中。
仅将 AppModule 中的模块或其他未直接导入您正在使用编辑器组件的模块中的模块导入是不够的。

【讨论】:

    【解决方案2】:

    创建一个共享模块并将 QuillModule 添加到其中的导入和导出部分,然后将共享模块附加到您需要使用 Quill 编辑器的每个模块

    @NgModule({
      imports: [        
        QuillModule.forRoot(),
      ],
      exports: [
        QuillModule
      ]
    })
    

    【讨论】:

      【解决方案3】:

      添加 formControlName 也很重要(如果您使用响应式表单): 就我而言 - 它有所帮助。

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2021-01-22
      • 2021-01-13
      • 2021-04-04
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 2021-01-15
      • 2019-06-18
      • 1970-01-01
      相关资源
      最近更新 更多