【问题标题】:Error: No component factory found for TermsConditions错误:没有为条款条件找到组件工厂
【发布时间】:2016-09-09 16:23:40
【问题描述】:

我收到此错误:

在使用 angular2-rc6 时没有找到符合条款条件的组件工厂。

我的路线图是这样的:

{
    path: '',
    component: TermsConditions
}

【问题讨论】:

  • 您在导出TermsConditions 组件吗?
  • @MadhuRanjan:你能解释一下为什么需要这样做吗? @NgModule({ imports: [ RouterModule ], declarations : [ TermsConditionsComponent ] }) 导出默认类 TermsConditions {}
  • declarations 用于在模块内使用该组件,exports 用于在外部使用它。您可以阅读更多关于模块 hereFAQ here 的信息,它们深入解释了这些概念。
  • @MadhuRanjan:谢谢,但在导出相同的内容后仍然得到相同的结果。 @NgModule({ declarations : [ TermsConditionsComponent ], exports: [ TermsConditionsComponent ] }) 导出默认类 TermsConditions {}
  • @Günter Zöchbauer 这似乎不像您引用的 Q 的副本。那是关于动态加载的组件,因为这是直接的模块配置。

标签: angular angular2-router3


【解决方案1】:

感谢您的帮助。我知道如何解决这个问题。

没有找到符合条款条件的组件工厂。

  @NgModule({ 
          declarations : [ TermsConditionsComponent ]
        }) 
        export default class TermsConditions {}
  1. 将此模块导入您的根模块。

       @NgModule({ 
          declarations : [ AppComponent ],
          imports: [ BrowserModule, TermsConditions ],
          bootstrap: [ AppComponent ]
        }) 
        export default class AppModule {}
    
  2. 在路由中使用组件。

    { 
      path : 'terms',
      component : TermsConditionsComponent
    }
    `
    

这意味着您的模块在应用程序范围内不可用,这就是您的组件未绑定到路由器的原因。

【讨论】:

    【解决方案2】:

    您需要在declarationsentryComponents 部分列出条款条件。

    https://stackoverflow.com/a/39376857

    【讨论】:

    • entryComponents 用于根级应用而不是子级应用。
    • entryComponents 用于列出任何组件树中模板中没有任何引用的组件。
    猜你喜欢
    • 2017-02-15
    • 2019-03-02
    • 1970-01-01
    • 2019-07-27
    • 2020-07-01
    • 2019-07-10
    • 2017-08-12
    • 2013-06-28
    • 2022-10-13
    相关资源
    最近更新 更多