在Angular中,可以创建一个自定义库,并在其中导出函数。以下是一个示例解决方法:
ng new my-library --create-application=false
cd my-library
ng generate library my-library
my-function.ts
。在该文件中,定义一个需要导出的函数。例如:export function myFunction(): void {
console.log('This is my custom function.');
}
export * from './lib/my-function';
ng build my-library
import { myFunction } from 'my-library';
// 在需要的地方调用函数
myFunction();
这样,就可以在Angular中使用自定义库并导出函数了。