【问题标题】:Why are Angular Component and Module class names for Entities prefixed with the application base name?为什么实体的 Angular 组件和模块类名称以应用程序基名称为前缀?
【发布时间】:2018-07-03 23:14:13
【问题描述】:

生成的 Angular 组件名称和模块名称以使用 JHipster 生成代码时指定的基本应用程序名称作为前缀,如下所示的生成项目的实体模块导入所示。

在生成的 entity.module.ts 文件的以下示例中,实体模块名称的前缀为“Gohomenotes”,因为我在生成代码时指定了基本应用程序名称“gohomenotes”。

@NgModule({
imports: [
    GohomenotesPersonModule,
    GohomenotesStudentModule,
    GohomenotesHomeRoomModule,
    GohomenotesTeacherModule,
    GohomenotesSchoolModule,
    GohomenotesHostRequestModule,
    GohomenotesGuestRequestModule,
    GohomenotesEarlyPickupRequestModule,
    GohomenotesTransportationChangeRequestModule,
    GohomenotesFamilyModule,
    GohomenotesFamilyMemberModule,
    GohomenotesAddressModule,
    GohomenotesPhoneNumberModule,
    GohomenotesGoHomeNotesSettingsModule

但是,相应的文件名不包括基本应用程序名称。这与 Angular 样式指南不一致,并使代码更难阅读 IMO。

除非有必要这样做的实际原因,我宁愿在组件和模块类名称上没有基本应用程序名称。如果我从模块和组件类名称中删除应用程序基名称是否有任何危害?

【问题讨论】:

    标签: jhipster


    【解决方案1】:

    我在 Gitter 上问了这个问题,得到了 Shaheen Georgee @1in9ui5t 的回答...

    为什么实体的 Angular 组件和模块类名称以应用程序基名称为前缀?

    “MyAppStudentModule”当我有一个名为“Student”的实体时,而不仅仅是“StudentModule”?

    最有可能避免与 Angular 应用程序中的其他模块发生潜在的命名冲突。例如,假设您正在处理一个医疗应用程序并且有一个测试实体来表示您的组织进行的一些医疗检查;如果您生成了一个 Test 实体(我知道这个名字很糟糕),那么生成的 test.module.ts 会导致命名冲突,因为已经有一个具有该名称的模块。

    我在这里猜测一下,我从过去查看 Jhipster 代码中知道有列入黑名单的术语。

    相关:Name collision by module import in Angular 2 - is there a way to prevent it

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2020-01-09
      • 2021-12-14
      • 2012-01-12
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      相关资源
      最近更新 更多