I tried creating my own module and import it like in app module below.
This code below is fine but I wanted to show an example and then propose my question below.
Suppose my folder structure is like below:- `
├── app
│ ├── app.component.ts
│ └── app.module.ts
├── credit-card
│ ├── credit-card-mask.pipe.ts
│ ├── credit-card.component.ts
│ ├── credit-card.module.ts
│ └── credit-card.service.ts
├── index.html
└── main.ts
`
My credit card module is like below:-
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CreditCardMaskPipe } from './credit-card-mask.pipe';
import { CreditCardService } from './credit-card.service';
import { CreditCardComponent } from './credit-card.component';
@NgModule({
imports: [CommonModule],
declarations: [
CreditCardMaskPipe,
CreditCardComponent
],
providers: [CreditCardService],
exports: [CreditCardComponent]
})
export class CreditCardModule {}
My app module is below:-
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CreditCardModule } from '../credit-card/credit-card.module';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
CreditCardModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
I tried to search for creating private modules in Angular2 over the internet but got no relevant information.
Unlike the module above I need to now implement a private module in my application.
Suppose I want my credit card module to be private so by removing the export word before class CreditCardModule will be enough to make my module private?
Let me know if I am right or wrong. Or is there any other way so my application can have private modules in angular2 app?
Also, I referred the page https://angular.io/guide/ngmodule-faq
What should I not export?
Don't export the following:
- Private components, directives, and pipes that you need only within components declared in this module. If you don't want another module to see it, don't export it.
- Non-declarable objects such as services, functions, configurations, and entity models.
- Components that are only loaded dynamically by the router or by bootstrapping. Such entry components can never be selected in another component's template. While there's no harm in exporting them, there's also no benefit.
- Pure service modules that don't have public (exported) declarations. For example, there's no point in re-exporting HttpModule because it doesn't export anything. It's only purpose is to add http service providers to the application as a whole.
But I am not clear.
Thanks in advance.