Angular 2 - 指令已声明但仍有错误

Angular 2 - Directives declared yet still have errors

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'

要么将 ScrollToWhen 添加到 ModuleA 的声明中,要么将其移动到一个模块中,然后您可以将其添加到 ModuleAimports: [...] 中以使其在那里可用。

一个 component/directive 只能在 declarations: [...] 中的 一个 模块中列出。然后在任何你想使用这个 component/directive.

的地方导入这个模块

对于用于声明指令和管道的模块,您需要在 exports 中设置它们,例如:

@NgModule({
    declarations: [
        myDirectives
    ],
    exports: [
        myDirectives
    ]
})