【发布时间】:2019-01-04 00:30:24
【问题描述】:
我有一个简单的 TypeScript 类,我想将它与一个模块一起打包,并最终使用 ng-packagr 将该模块导出为一个库。
例如我的班级定义是 -
export class Params {
language: string ;
country: string ;
variant: string ;
dateFormat: string ;
briefDateTimeFormat: string ;
decimalFormat: string ;
}
例如我的模块定义是 -
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Params } from '../params/params';
import { LoginService } from '../sso/login.service';
@NgModule({
imports: [CommonModule],
exports: [Params],
providers: [LoginService]
declarations: [Params, LoginService]
})
export class FoundationModule { }
但是当我尝试在ng-packagr 的public-api.ts 中导出FoundationModule 时,出现以下错误 -
BUILD ERROR
: Unexpected value 'Params in .../params/params.ts' declared by the module 'FoundationModule' in '.../foundation.module.ts'. Please add a @Pipe/@Directive/@Component annotation.
如何在 Angular 模块中打包单个类?
【问题讨论】:
-
不确定是否必须创建构造函数来完成类,另一种选择是将其保留为接口。
-
我认为您需要添加 export * from '../params/param'。我使用它来导出我的类以进行汇总,以获得平面 es 模块
-
您混淆了 Angular 模块和 es 模块。此外,Params 不应该是一个类。使用
interface
标签: angular typescript angular-module ng-packagr