如何在Angular2中的模块下导出类


遇见你
2025-03-12 05:56:40 (27天前)


我在尝试将模块下的类导出到另一个模块时遇到问题。问题是有一个错误说导入的模块不是模块。

这是模块

///& …

2 条回复
  1. 0# Ni | 2019-08-31 10-32



    模块在Angular-Framework中有另一个目的。这是错误的,并且无法在模块中定义要在系统中的其他位置导入的类。



    您定义的帮助程序类必须放在单独的文件或服务中。



    例如



    辅助性classes.ts




    1. export class _LoginHelper {
      // …
      }

    2. export class _RegistrationHelper {

    3. static register(metadataStore) {
    4. metadataStore.registerEntityTypeCtor('sensor_location', LATS.DataModel.sensor_location);
    5. }
    6. }

    7. //…

    8. </code>


    要么



    helper.service.ts




    1. //… Service-Header and imports

    2. public login(user) {
      //…
      }

    3. public register(metadataStore) {
      metadataStore.registerEntityTypeCtor(‘sensor_location’, LATS.DataModel.sensor_location);
      }
      }

    4. </code>


    然后从TS-File导出该类,或者在需要该方法的任何地方使用该方法。


登录 后才能参与评论