1

I am developing an Angular6 library to be used as the basis of many internal websites. It will be providing mostly services, but also provide a few components.

I want to create a Demo App for this library that can demonstrate various ways of using the services, in the same way that a Component library would demonstrate the various ways of using the components.

The problem is that these services were designed to be providedIn root, making them singletons at root. This makes it hard to have a Demo App that can show different service behaviors in different routes, without hard-restarting the application in the browser.

Is there a strategy I can use to make my library act normally when used within an Application (app.module) but be able to constructed/destructed within a Demo App?

If I create a LibraryRootModule and then set everything to be providedIn LibraryRootModule, would that help? How would AOT work with that? I'm also concerned that third-party dependencies that use providedIn root may not work well alongside this strategy.

Any insights would be appreciated. Thanks.

Pait
  • 31
  • 2

1 Answers1

0

1) May be you should use forRoot() pattern: https://angular.io/guide/singleton-services#the-forroot-pattern;

2) May be you should use different Angular app on the one website. And use Platform Injector: https://blog.angularindepth.com/angular-dependency-injection-and-tree-shakeable-tokens-4588a8f70d5d

Hope it's help!

Dmitriy Ivanko
  • 950
  • 8
  • 17