2016-09-09 28 views
1

我收到此错误:错误:未元件厂发现TermsConditions

No component factory found for TermsConditions while using angular2-rc6.

我的路线图是这样的:

{ 
    path: '', 
    component: TermsConditions 
} 
+0

您是否在导出'TermsConditions'组件? –

+0

@MadhuRanjan:你能解释一下为什么这是必需的吗? @NgModule({ 进口:[RouterModule], 声明: TermsConditionsComponent ] }) 出口默认类TermsConditions {} –

+0

'declarations'是使用模块内的部件,和'exports'是用于使用它外部。你可以阅读更多关于模块[这里](https://angular.io/docs/ts/latest/guide/ngmodule.html)和[常见问题](https://angular.io/docs/ts/latest/ cookbook/ngmodule-faq.html),他们深入地解释了这些概念。 –

回答

5

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

No component factory found for TermsConditions.

@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

+0

entryComponents用于根级别的应用程序,不适用于子级别的应用程序。 –

+0

但是它的工作方式 – Yougesh

+0

entryComponents用于列出在任何组件树的模板中没有任何引用的组件。 –