-1

I want to create a common module which will contain components like login, sidebar etc and pipes, services, directives.

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    SidebarComponent,
    InitialsPipe
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  bootstrap: [AppComponent]
})
export class CompanyCommonModule { }

Now, I want to use it in other projects like:

import { CompanyCommonModule } from 'company-common-module';
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79

1 Answers1

3

You should use a library to do that: https://angular.io/guide/creating-libraries

J. S.
  • 2,268
  • 1
  • 12
  • 27
  • We need to create a library within a project. So lets say I have created one library in Project A. After building, it resides within dist folder. For using it (without publishing) in Project B, shall I have to copy it in dist folder of Project B and then use? – Adrita Sharma Jan 15 '19 at 09:37
  • You can just link to the library, best solution would be to use TypeScript path mapping. Generally I would recommend to use angular-cli workspace, you can generate multiple projects and libraries and they share one tsconfig. When you build a library a path mapping will be generated and you can just use `import {..} from 'my-lib` in every project. Here some Info about workspaces: https://angular.io/guide/file-structure – J. S. Jan 15 '19 at 10:19
  • Thanks for the info – Adrita Sharma Jan 15 '19 at 10:22