如何在 shared.module 中导出函数?

问题描述

我有以下功能

export function toCamelCase(string): string {
  //code omitted
}

然后我通过添加引用在我的功能组件上使用它:

import * as utility from '../shared/functions/helper-functions';

但是,我使用共享模块,我想知道是否可以将此辅助函数引用仅添加到共享模块并将其导出,以便我可以在不添加其引用的情况下使用其函数(我已经添加了 shared.module 引用)。有什么想法吗?

import * as utility from '../shared/functions/helper-functions';

@NgModule({
  declarations: [
    //...
  ],imports: [
    //...
  ],exports:  [
    // I want to add helper function as a module    
  ],providers: [
    //...
})
export class SharedModule { }

解决方法

也只有 export class SharedModuleexport * from '../shared/functions/helper-functions'

如果您真的想在 Angular 模块中公开辅助函数,您可以将它们公开为服务(在 providers 部分中),但这实际上没有意义。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...