对象文字只能指定已知属性,并且“NgModule”类型中不存在“entryComponents”

问题描述 投票:0回答:1

将 Angular 版本从 11 升级到 17.3.8 后,无论在 @NgModule 中使用入口组件,它都会在我的代码中抛出错误行。因为它在本地运行时会在所有 npm 模块中抛出错误。

import { NgModule } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
import { Ng2SmartTableModule } from 'ng2-smart-table';
import { ThemeModule } from '../../@theme/theme.module';
import { FormsModule } from '@angular/forms';
import { UsersComponent } from './users.component';
import { NbCardModule, NbButtonModule, NbSelectModule, NbInputModule, NbSpinnerModule } from '@nebular/theme';
import { AddUserComponent } from './add-user/add-user.component';
import { EditUserComponent } from './edit-user/edit-user.component';
import { DeleteUserComponent } from './delete-user/delete-user.component';

const COMPONENTS = [
  UsersComponent,
  AddUserComponent,
  EditUserComponent,
  DeleteUserComponent,
];

const ENTRY_COMPONENTS = [
  AddUserComponent,
  EditUserComponent,
  DeleteUserComponent,
];

const MODULES = [
  CommonModule,
  ThemeModule,
  NgbModule,
  NbButtonModule,
  NbSelectModule,
  NbInputModule,
  NbCardModule,
  Ng2SmartTableModule,
  FormsModule,
  NbSpinnerModule
];

@NgModule({
  imports: [...MODULES],
  declarations: [...COMPONENTS,],
  entryComponents: [...ENTRY_COMPONENTS]
})
export class UsersModule { }
angular npm object-literal ng-modules ng
1个回答
0
投票
更高版本的 Angular 不再需要

entryComponents

因此,请从所有模块中删除

entryComponents

还将这些组件转换为

standalone: true
,然后您可以动态创建它们或将它们添加到任何模块的导入数组中。

@Component({
  selector: 'app-entry-comp',
  standalone: true,
  template: `
    <h1>Hello from {{ name }}!</h1>
    <a target="_blank" href="https://angular.dev/overview">
      Learn more about Angular
    </a>
  `,
})
export class EntryComponent {
  name = 'Angular';
}
© www.soinside.com 2019 - 2024. All rights reserved.