ngParty / ng-metadata

Angular 2 decorators and utils for Angular 1.x
https://hotell.gitbooks.io/ng-metadata/content/
MIT License
355 stars 46 forks source link

Nested Modules do not expose services from other modules correctly #208

Open DaSchTour opened 7 years ago

DaSchTour commented 7 years ago

I made a small example here https://plnkr.co/edit/ER3t3jLJAhN2myR9FIXY

The hierarchy of modules doesn't work because the service imported through a module in a child module is lost when bootstraping the parent module. So there is not possibility to inherit services from submodules correctly.

aciccarello commented 7 years ago

I've been getting that InvalidProviderError(undefined) a lot lately. I think it is more of a TypeScript issue. The modules provided to NgMetadata are undefined if there is a cycle in the imports or the modules are defined in the wrong order. Since the modules aren't defined independently the symbols need to be defined at boot time so NgMetadata can bundle them.

I reorganized the app.module.ts in your plunker and changed the bootstrap to the AppModule to get things working. https://plnkr.co/edit/9FCvm9zbpxu05CLiKbhR?p=preview

DaSchTour commented 7 years ago

@aciccarello okay, well. That makes my problem even worse. I've separated NPM Packages using ng-metadata ngModule definition. So the best way would be to import all dependencies needed in the base module and don't depend on resolving imports of submodules. Or may it be possible use ngmodules export property to add the submodules so that the import is expanded to also importing all submodules.

aciccarello commented 7 years ago

I'm not sure I understand what issue you are referring to. Can you create another plunker?

You should be able to import modules in the dependencies. The difficulty is when you bundle the NgMetadata modules separately or have a circular dependency.

DaSchTour commented 7 years ago

@aciccarello yes that's exactly what I'm doing. The punklr I made is just an example of seperate NPM packages using NgMetadata modules. But the point with circular dependencies is a point I have to check, although the structure of our packages should be hierarchical.

DaSchTour commented 6 years ago

@aciccarello Is it possible to extend the error message of InvalidProviderError(undefined) to get some kind of stacktrace? Some information about the module, component or module where this happend would be very helpful.

aciccarello commented 6 years ago

:+1: Yeah, I think the error message could be improved. I would like for the error message to include something about the module where undefined was found. Maybe if the type is undefined there could be a special error message suggesting that there was a cycle in the imports.