Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share a module between multiple angular apps that resides in the same project

This question has been asked before but needs more clarity, is it somehow possible to reuse modules or single components from a angular-cli app to another?

Since its now possible to have multiple apps i one angular-cli project, I took advantage by this to be able to build two different types of bundles for production.

My project looks like this:

src
 |─app-core
 |   |────shared
 |   |       |────share-this.component.ts
 |   |       |────shared.module.ts
 |   |       
 |   |────app.module.ts
 |   |────app-root.component.ts
 |   
 └─app-inspection
     |────app.module.ts (how do I use 'share-this.component.ts' here?)
     |────app-root.component.ts

When importing the SharedModule in the app-inspections AppModule the services isn't provided somehow.

I know a npm-package would solve my problem but I think it should be easier than this.

So, is there anyone who sits on a solution? Otherwise maybe a feature Angular could build?

Link to the other question

like image 518
JulianSim Avatar asked May 17 '17 07:05

JulianSim


People also ask

Can we have multiple app modules in Angular?

Only one root module can exist in an Angular application.

How do you share Angular components between projects and apps?

To get started, go ahead and install bit-cli, then head over to the project from which to share the components, and initialize a bit workspace. Then, head over to bit. dev and create a free account. Then, create a collection to host your shared components.

What is the use of shared module in Angular?

Creating shared modules allows you to organize and streamline your code. You can put commonly used directives, pipes, and components into one module and then import just that module wherever you need it in other parts of your application.


1 Answers

As Niel Lunn said in his comment, the solution was "Just import relative to the path". So this leads to that you can reuse your modules over apps that resides in one project!

Check here to see how you create multiple apps in one project.

like image 188
JulianSim Avatar answered Sep 28 '22 05:09

JulianSim