-2

I've been working with Angular for some time. I feel that my modularization lack some whim. I spent some time studying NgModule and its properties and I felt confident to try to upgrade the modularization of my app but it didn't work the way I expected. The first thing that annoys me is that I have several imports of models in each component ts file example

component ts

 import {Object, Tool, Color, SearchOption ...etc}  from '..someplace';

I tried to create a module to include all of my models

@NgModule(
{
  provider: [Object, Tool, Color, SearchOptions]
}
)
export class ModelModule{
}

Then I imported that module into the module of a feature Module

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
   
    ModelModule
  ],


})
export class ResultSearch { }

But my Component class complains about the missing types this is the component related to the module that imported the 'model module'. For me importing the model module would allow me to avoid the imports.

@Component({
select: 'someselector'
  })
export class Search{
  tool: Tool  <<--- cannot find name 'Tool'
}

I will give an idea of my structure.

 /model
   --model.module.ts <<-- all the models are include here
   --tool.model.ts
   --color.model.ts
/result
   --result.module.ts    <<-- I import the model module here
   --result.component.ts  <<-- My desire was to avoid the imports here on the component
Diego Alves
  • 2,462
  • 3
  • 32
  • 65

1 Answers1

0

The ES module format is the official standard format to package JavaScript code and for Typescript code either. If you use interfaces/class definitions in separate files, you just have to import its notation. Nothing wrong with it.

Anton Marinenko
  • 2,749
  • 1
  • 10
  • 16