Angular2,在延迟加载的模块中使用coreModule组件

时间:2017-05-21 15:52:59

标签: angular angular-components

我的结构类似于https://angular.io/docs/ts/latest/guide/style-guide.html#04-11

src
  app
    core
      core.module.ts
       spinner
         spinner.component.ts|html|css|spec.ts
         spinner.service.ts|spec.ts
    product
      product-list.component.ts
      product.module.ts
  app.component.ts|html|css|spec.ts
  app.module.ts
  app-routing.module.ts
  main.ts
  index.html
...

当路线为product-module时,模块/product/list将加载LAZY。现在,在产品组件模板中,我正在尝试使用核心组件spinner,但我收到以下错误:

Error: Template parse errors:'spinner' is not a known element:

我认为这是因为CoreModule中未导入ProductModule,但CoreModule已导入AppModule

导入CoreModule中的ProductModule时,工作正常。

我的问题是:

  • 核心模块不应只在AppModule中导入一次?
  • 如何在核心模块中导出组件以允许在任何地方使用,而无需每次都进行导入?

EDIT1:

读这个(https://angular.io/docs/ts/latest/guide/ngmodule.html#!#add-the-contactmodule)我可以看到:

  

模块不会继承对其他模块中声明的组件,指令或管道的访问权限。 AppModule导入的内容与ContactModule无关,反之亦然。在ContactComponent可以与[(ngModel)]绑定之前,其ContactModule必须导入FormsModule。

阅读上述内容,我认为需要导入我的CoreBundle来使用他们的组件。

但在其他文件中说(https://angular.io/docs/ts/latest/guide/style-guide.html#04-12

  

只有根AppModule才能导入CoreModule。

这有点矛盾,除非spinner只能在AppComponent中使用,在这种情况下,为什么将微调器放在coreModule而不是直接放在AppModule中。

我错过了什么......?

0 个答案:

没有答案