【发布时间】:2016-09-01 10:05:32
【问题描述】:
在RootModule:
@NgModule({
imports: [
ModuleA
],
declarations: [
ScrollToWhen
],
bootstrap: [BootComponent],
})
class RootModule {}
在模块 A 内的一个组件模板中,我使用 ScrollToWhen,但出现错误:Can't bind to 'scrollToWhen' since it isn't a known property of 'div'。
为什么?
Error: Unexpected directive 'HbClass' imported by the module 'Module'
【问题讨论】:
-
我们需要更多信息,你如何使用指令,指令的代码是什么样的,...
-
最好是通过代码而不是截图。
HbClass、Default、Asset、Photon是模块吗?你有它们在declarations在RootModule和imports在Module。imports用于模块,declarations用于指令、组件和管道。 -
所以我应该创建一个
MyAppCommonModule并在其中声明所有常用的指令和管道,然后在需要时导入到模块? -
就是这样。
标签: angular angular2-directives