How can i export a class to module and import the same in another module in typescript with angular

praveen picture praveen · Apr 26, 2017 · Viewed 14.3k times · Source

I have a class(IGeneric) which is exported to the module A and I imported that Module(A) in module B, but I could not use that exported class(IGeneric) in the module B.

Note : that exported class is not a component,directive and service.it is a plain typescript class

Any help will be appreciated, thanks in advance. The class which I am trying to export

export class IGeneric{
header : any[];
content : [{
   lable :any,
   value :any
}]
}

Answer

Hearen picture Hearen · Feb 3, 2019

There is a trick to hide the details within a module by barrel files, via which you can

  • just introduce the barrel file (normally named as index.ts) to that module, and
  • export everything you intend to export in that barrel file, and then
  • import the module path whenever you try to use the exported class/interface or components;

As a follow-up, there is an another answer to elaborate what you can achieve by using barrel files.