我想制作一个具有一堆实用方法的通用模块,包括 moment 和 lodash 功能。我已经导入了 lodash 并输入了它,只要包含代码,我就可以从我的组件中访问它:
import * as _ from "lodash";
但是,我想让它更通用,这样我就可以导入我的 Utils 模块并同时使用 lodash 和 moment(以及一些自定义函数),而不必在每个组件中单独导入它们。
我有以下代码:
import { Injectable, NgModule } from "@angular/core";
import * as _ from "lodash";
import * as _ from "moment";
@Injectable()
@NgModule({
exports: [_, moment]
})
export class Utils { }
}
我收到以下错误:
Build:Argument of type '{ exports: LoDashStatic[] 1>; }'
is not assignable to parameter of type 'NgModule'
编辑:我想做的是:
import { _, moment } from "./Utils.module";
代替
import * as _ from "lodash";
import * as moment from "moment";
我怎样才能做到这一点?
编辑:使代码更多地反映了我想要完成的事情......