我有一个常量,其他导入我的模块应该可以使用它。
我有 Datepicker 指令,它定义了日期格式常量(我有这样的,所以使用我的指令的人可以使用这些常量):
export const DATETIME_FORMAT = 'DD/MM/YYYY HH:mm:ss';
export const DATE_FORMAT = 'DD/MM/YYYY';
export const TIME_FORMAT = 'DD/MM/YYYY';
NgModule 用于进一步导出它们。该模块被构建,然后在其他项目/模块中使用。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DatepickerDirective, TIME_FORMAT, DATETIME_FORMAT, DATE_FORMAT } from './datepicker.directive';
@NgModule({
imports: [
CommonModule
],
exports: [
DatepickerDirective,
DATE_FORMAT,
DATETIME_FORMAT,
TIME_FORMAT
],
declarations: [
DatepickerDirective
]
})
export class DatepickerModule { }
但是在尝试构建它时,我得到了错误:
ERROR in src/app/datepicker/datepicker.module.ts(5,11): error TS2345: Argument of type '{ imports: (typeof CommonModule)[]; exports: (string | typeof DatepickerDirective)[]; declara...' is not assignable to parameter of type 'NgModule'.
Types of property 'exports' are incompatible.
Type '(string | typeof DatepickerDirective)[]' is not assignable to type '(any[] | Type<any>)[]'.
Type 'string | typeof DatepickerDirective' is not assignable to type 'any[] | Type<any>'.
Type 'string' is not assignable to type 'any[] | Type<any>'.