Angular 中的声明和指令有什么区别?

What is difference between declarations and directives in Angular?

我一直在看一些关于如何编写正确的 Angular 应用程序的教程,但是一些参考组件中的指令,而其他参考模块中的声明。

指令不再存在,取而代之的是声明。

指令曾经是组件级别 configuration/declaration,它定义了将在当前组件的视图中使用的 directives/component。

但是当 NgModule 进入 2.0.0 时,它取代了指令,你应该在 NgModule 中声明你所有的指令和组件

因此,如果您看到如下教程:

@Component({

   directives : [SomeComponent, SomeDirectives]
})

您可以在该组件的 NgModule 中考虑该列表,如下所示:

@NgModule({
   declarations:[SomeComponent, SomeDirectives]
})

并将其从组件中移除