سازماندهی برنامههای Angular توسط ماژولها
نویسنده: وحید نصیری
تاریخ: ۱۳۹۶/۰۸/۰۷ ۱۲:۲۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { UserRepositoryService } from './user-repository.service';
import { NavBarComponent } from './nav-bar.component';
import { AccountMenuComponent } from './account-menu.component';
@NgModule({
imports: [ CommonModule, RouterModule ],
exports: [ NavBarComponent, AccountMenuComponent ],
declarations: [ NavBarComponent, AccountMenuComponent ],
providers: [ UserRepositoryService ]
})
export class CoreModule { }; import { CoreModule } from "./core/core.module";
@NgModule({
imports: [
//...
CoreModule,
//...
RouterModule.forRoot(appRoutes)
],
//...
})
export class AppModule { } import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LoadingSpinnerComponent } from './loading-spinner.component';
@NgModule({
imports: [ CommonModule ],
declarations: [ LoadingSpinnerComponent ],
exports: [ LoadingSpinnerComponent, CommonModule ],
providers: [ ]
})
export class SharedModule { }; import { CoreModule } from "./core/core.module";
import { SharedModule } from "./shared/shared.module";
@NgModule({
imports: [
//...
CoreModule,
SharedModule,
//...
RouterModule.forRoot(appRoutes)
],
//...
})
export class AppModule { } > ng g m users -m app.module --routing > ng g c users/users-list
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { SharedModule } from '../shared/shared.module';
import { UsersListComponent } from './users-list.component';
@NgModule({
imports: [ RouterModule, SharedModule ],
declarations: [ UsersListComponent ],
exports: [ ],
providers: [ ]
})
export class UsersModule { }; providers: [ UserRepositoryService ]
@NgModule({
imports: [CommonModule, RouterModule],
exports: [], // components that are used in app.component.ts will be listed here.
declarations: [], // components that are used in app.component.ts will be listed here.
providers: [BrowserStorageService, AppConfigService] // global singleton services of the whole app will be listed here.
})
export class CoreModule {
constructor( @Optional() @SkipSelf() core: CoreModule) {
if (core) {
throw new Error("CoreModule should be imported ONLY in AppModule.");
}
}
}; @NgModule({
imports: [CommonModule],
declarations: [], // common and shared components/directives/pipes between more than one module and components will be listed here.
exports: [CommonModule], // common and shared components/directives/pipes between more than one module and components will be listed here.
/* No providers here! Since they’ll be already provided in AppModule. */
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
// Forcing the whole app to use the returned providers from the AppModule only.
return {
ngModule: SharedModule,
providers: [ /* All of your services here. It will hold the services needed by `itself`. */]
};
}
};
سپاس از شما
├───authentication │ ├───access-denied │ └───login ├───core │ ├───component │ │ └───header │ ├───models │ └───services ├───dashboard │ ├───call-protected-api │ └───protected-page ├───page-not-found ├───shared │ └───directives └───welcome
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class MyCoreService { } @Injectable({
providedIn: 'root',
useClass: LazyFlightCancellingService,
deps: [NgModuleFactoryLoader, Injector]
})
export class FlightCancellingService { }