作angular demo报错: Uncaught Error: Unexpected directive 'ScrollSpyDirective' imported by the module 'AppModule'. Please add a @NgModule annotation。解决问题时发现对@NgModule中import、declarations、providers这三个配置信息理解不是很到位。特此整理下。npm
每一个模块的@NgModule中都会包含import、declarations、providers三个配置节,他们的具体含义为:app
import:当前模块导入的其余模块,import应该导入的是module,而不是compnents或者serviceside
declarations:当前模块内包含的公共组件、指令信息。declarations生命的是components,而不是module或者servicescomponent
providers:当前模块能够使用的公共服务(能够为本模块内提供的服务,也能够是其余npm包中导入的服务)。provider提供的应该是services,而不是compnents或者modules。blog
了解了以上信息此问题的缘由就很清晰了,ScrollSpyDirective属于本模块内的组件。引入ScrollSpyDirective应该在declarations中生命而不该该在import中引入。get