HttpClientModule’ declared by the module ‘AppModule’. Please add a @Pipe/@Directive/@Component annot
这是app.module.ts文件
@NgModule({
declarations: [
AppComponent,
ProductListComponent,
ProductDetailsComponent,
ProductAlertsComponent,
CartInfoComponent,
],
imports: [ //注意这个和前面的declarations的区别
BrowserModule,
HttpClientModule,
RouterModule.forRoot(routes)
],
providers: [],
bootstrap: [AppComponent]
})
如果你出现了这样的错,那你注意了,HttpClientModule是引入的模块,不是自己创建的组件,所以要放在import的里面而不是declarations,
同理如果你的其他组件报错那说明你把组件也放错地方了
希望对新手有帮助