Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

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

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
}]
}
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Santiago Trujillo Denunciar

0

index file will be helpful to you if you don't want to show the entire path of your class

Assume that you have a module MyModule within which you have IGeneric class

igeneric.model.ts

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

Index file should be inside your Module MyModule directory

index.ts

export * from 'app/MyModule/igeneric.model';

Then in your component you can import

import {IGeneric} from 'app/MyModule'
about 4 years ago · Santiago Trujillo Denunciar

0

This looks like an ES6/Typescript module import/export issue rather than an issue for (the completely different and separate) NgModule system. If this is the case, then you simply need to import the class you want from the file you want at the top of the .ts file, e.g.:

import { IGeneric } from './relative/path/to/definition';

and then use the class as you would normally in a component/service etc

public generic: IGeneric;
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda