我尝试遵循 Angular 的“入门”示例项目:https://angular.io/start#getting-started-with-angular
在“将数据传递到子组件”部分中,我在第 7 步中失败了。它显示“生成器自动将 ProductAlertsComponent 添加到 AppModule,以使其可供应用程序中的其他组件使用。”然而,在我的 StackBlitz 项目中,情况并非如此。代码片段中显示的更改在我的项目中不存在。 当我手动添加更改时,添加后出现错误
import { ProductAlertsComponent } from './product-alerts/product-alerts.component';
@NgModule({
declarations: [
AppComponent,
TopBarComponent,
ProductListComponent,
ProductAlertsComponent,
],
到
src/app/app.module.ts
终端显示错误
Application bundle generation failed. [0.193 secon
✘ [ERROR] TS-996008: Component ProductAlertsComponent is standalone, and cannot be declared in an NgModule. Did you mean to import it instead? [plugin angular-compiler]
src/app/app.module.ts:23:4:
23 │ ProductAlertsComponent
但是,我也将其添加到导入部分,如上所示。
我对 Angular 完全陌生(因此有了教程),但这真的很令人沮丧。