1

I am creating some angular schematics for my project to create all required services/components with all imports etc. The problem is that I use index file to import all services etc and my structure might look like this:

| src
|
|-- app
    |
    |-- module
           |
           |-- components
           |      |
           |      |-- index.ts
           |      |-- component1
           |      |     |
           |      |     |-- component1.component.ts
           |      |
           |      |-- component2
           |      |     |
           |      |     |-- component2.component.ts
           |
           |
           |-- services
                  |
                  |-- index.ts
                  |-- service1
                  |-- service2

Right now when I create 1st component in module it works great, but when I create 2nd I get an error telling me that file index.ts exists. I have tried different merge strategies but neither appends the file and I always get same issue.

Right now I keep all my index.ts files together with other templates. Is there any good practice/way to do it or do I need to manually find if file exists and if so open it and edit? Or is there a 'fast way'?

Chaki
  • 73
  • 6
  • What exactly is the use for index.ts? you import all your dependencies in you modules. Is index.ts a import simplifier, or the root html? what is the purpose of the file – Jonas Praem Jan 18 '19 at 13:29
  • The reason is to have cleaner imports in the app. For example in services/index.ts I have imports of all services: export * from ./services/serviceA export * from ./services/serviceB export * from ./services/serviceC This allows us to have imports in component/wherever look like: import { ServiceA, ServiceB, ServiceC} from '../services'; instead having it spread between multiple statements basically this: https://medium.com/@balramchavan/smarter-way-to-organize-import-statements-using-index-ts-file-s-in-angular-c685e9d645b7 – Chaki Jan 18 '19 at 13:58
  • Can you provide your module code? – Jonas Praem Jan 18 '19 at 19:58
  • I dont really understand how this is relevant to the problem but here is the module code: https://pastebin.com/k4s21300 – Chaki Jan 21 '19 at 07:02

0 Answers0