Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

add example of CoreModule
Source Link
mickdev
  • 2.9k
  • 14
  • 16

I think this question is too general and for general question, you'll have general answers ... For example, shared module is meant to keep what several components/modules use :

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
//import { AwesomePipe } from './awesome.pipe';
//import { HighlightDirective } from './highlight.directive';
@NgModule({
 exports: [ /*AwesomePipe, HighlightDirective,*/
 CommonModule, FormsModule, ReactiveFormsModule ]
})
export class SharedModule { }

CoreModule is more like what you consider to be the core of your page (Nav, Spinner, Alert...). This is very suggestive and depend on your feeling I think. For example:

import { NgModule, Optional, SkipSelf } from '@angular/core';
import { NavComponent } from './nav/nav.component';
import { SpinnerComponent } from './spinner/spinner.component';
import { SpinnerService } from './spinner/spinner.service';
import { AlertComponent } from './alert/alert.component';
import { AlertService } from './alert/alert.service';
import { SharedModule } from '../shared/shared.module';
import { CoreRoutingModule } from './core-routing.module';
@NgModule({
 imports: [ 
 SharedModule, 
 CoreRoutingModule,
 ],
 exports: [//Other modules use these components, so we export them
 AlertComponent, 
 NavComponent, 
 SpinnerComponent,
 ],
 declarations: [ //we use them in CoreModule, so we declare them
 AlertComponent, 
 NavComponent, 
 SpinnerComponent,
 ],
 providers: [
 SpinnerService, 
 AlertService,
 ]
})
export class CoreModule {
 constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
 if (parentModule) {
 throw new Error(
 'CoreModule est déjà chargé. Importer le uniquement dans AppModule');
 }
 }
}

I think this question is too general and for general question, you'll have general answers ... For example, shared module is meant to keep what several components/modules use :

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
//import { AwesomePipe } from './awesome.pipe';
//import { HighlightDirective } from './highlight.directive';
@NgModule({
 exports: [ /*AwesomePipe, HighlightDirective,*/
 CommonModule, FormsModule, ReactiveFormsModule ]
})
export class SharedModule { }

CoreModule is more like what you consider to be the core of your page (Nav, Spinner, Alert...). This is very suggestive and depend on your feeling I think.

I think this question is too general and for general question, you'll have general answers ... For example, shared module is meant to keep what several components/modules use :

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
//import { AwesomePipe } from './awesome.pipe';
//import { HighlightDirective } from './highlight.directive';
@NgModule({
 exports: [ /*AwesomePipe, HighlightDirective,*/
 CommonModule, FormsModule, ReactiveFormsModule ]
})
export class SharedModule { }

CoreModule is more like what you consider to be the core of your page (Nav, Spinner, Alert...). This is very suggestive and depend on your feeling I think. For example:

import { NgModule, Optional, SkipSelf } from '@angular/core';
import { NavComponent } from './nav/nav.component';
import { SpinnerComponent } from './spinner/spinner.component';
import { SpinnerService } from './spinner/spinner.service';
import { AlertComponent } from './alert/alert.component';
import { AlertService } from './alert/alert.service';
import { SharedModule } from '../shared/shared.module';
import { CoreRoutingModule } from './core-routing.module';
@NgModule({
 imports: [ 
 SharedModule, 
 CoreRoutingModule,
 ],
 exports: [//Other modules use these components, so we export them
 AlertComponent, 
 NavComponent, 
 SpinnerComponent,
 ],
 declarations: [ //we use them in CoreModule, so we declare them
 AlertComponent, 
 NavComponent, 
 SpinnerComponent,
 ],
 providers: [
 SpinnerService, 
 AlertService,
 ]
})
export class CoreModule {
 constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
 if (parentModule) {
 throw new Error(
 'CoreModule est déjà chargé. Importer le uniquement dans AppModule');
 }
 }
}
Source Link
mickdev
  • 2.9k
  • 14
  • 16

I think this question is too general and for general question, you'll have general answers ... For example, shared module is meant to keep what several components/modules use :

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
//import { AwesomePipe } from './awesome.pipe';
//import { HighlightDirective } from './highlight.directive';
@NgModule({
 exports: [ /*AwesomePipe, HighlightDirective,*/
 CommonModule, FormsModule, ReactiveFormsModule ]
})
export class SharedModule { }

CoreModule is more like what you consider to be the core of your page (Nav, Spinner, Alert...). This is very suggestive and depend on your feeling I think.

lang-js

AltStyle によって変換されたページ (->オリジナル) /