我有一个类(IGeneric
),其被输出到模块A和I导入的模块(A)在模块B,但我不能在模块B.使用该导出的类(IGeneric
)
注意:出口类不是一个组件,指令和service.it是一个普通的打字稿类
任何帮助将提前赞赏,感谢。而我试图出口类
export class IGeneric{
header : any[];
content : [{
lable :any,
value :any
}]
}
这看起来像一个ES6 /打字稿模块导入/导出问题,而不是对(完全不同的和独立的)NgModule系统的问题。如果是这样的话,那么你只需要import
你从你想在的.ts文件,e.g顶部的文件所需的类:
import { IGeneric } from './relative/path/to/definition';
然后使用类,你通常会在一个组件/服务等
public generic: IGeneric;
index
文件将会对你有所帮助,如果你不希望显示类的完整路径
假设你有内,你必须MyModule
类模块IGeneric
igeneric.model.ts
export class IGeneric{
header : any[];
content : [{
lable :any,
value :any
}]
索引文件应该是你的模块MyModule
目录内
index.ts
export * from 'app/MyModule/igeneric.model';
然后在你的组件,你可以导入
import {IGeneric} from 'app/MyModule'
还有一招来隐藏barrel files
一个模块内的细节,通过它你可以
index.ts
)到该模块,并作为后续,有一个又一个answer阐述什么,你可以通过使用桶文件实现。