Last active
November 1, 2020 12:16
-
-
Save LayZeeDK/291a1d0230de81bf2cf89256070ce569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject } from '@angular/core'; | |
import { configToken } from './config.token'; | |
import { Config } from './config'; | |
@Injectable({ | |
providedIn: 'any', // π Tree-shakable, only bundled if used | |
}) | |
export class ConfigService { | |
constructor(@Inject(configToken) private config: Config) { | |
console.log('new instance is created'); | |
} | |
getValue() { | |
return this.config; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { NgModule } from '@angular/core'; | |
import { configToken } from '../shared/config.token'; | |
import { Config } from '../shared/config'; | |
import { DepartmentRoutingModule } from './department-routing.module'; | |
import { DepartmentComponent } from './department.component'; | |
export const configValue: Config = { | |
apiEndPoint: 'xyz.com', | |
timeout: 4000, | |
}; | |
@NgModule({ | |
declarations: [ | |
DepartmentComponent, | |
], | |
imports: [ | |
CommonModule, | |
DepartmentRoutingModule, | |
], | |
providers: [ | |
{ | |
provide: configToken, useValue: configValue, | |
}, | |
], | |
}) | |
export class DepartmentModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject } from '@angular/core'; | |
import { configToken } from './config.token'; | |
import { Config } from './config'; | |
@Injectable() | |
export class ConfigService { | |
constructor(@Inject(configToken) private config: Config) { | |
console.log('new instance is created'); | |
} | |
getValue() { | |
return this.config; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { NgModule } from '@angular/core'; | |
import { ConfigService } from '../shared/config.service'; | |
import { configToken } from '../shared/config.token'; | |
import { Config } from '../shared/config'; | |
import { DepartmentRoutingModule } from './department-routing.module'; | |
import { DepartmentComponent } from './department.component'; | |
export const configValue: Config = { | |
apiEndPoint: 'xyz.com', | |
timeout: 4000, | |
}; | |
@NgModule({ | |
declarations: [DepartmentComponent], | |
imports: [ | |
CommonModule, | |
DepartmentRoutingModule, | |
], | |
providers: [ | |
{ provide: configToken, useValue: configValue }, | |
ConfigService, // π Always bundled, even if unused | |
], | |
}) | |
export class DepartmentModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { ConfigService } from './config.service'; | |
@NgModule() | |
export class ConfigModule { | |
static forChild(): ModuleWithProviders<ConfigModule> { | |
return { | |
ngModule: ConfigChildModule, | |
providers: [ | |
ConfigService, // π Always bundled, even if unused | |
], | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject } from '@angular/core'; | |
import { configToken } from './config.token'; | |
import { Config } from './config'; | |
@Injectable() | |
export class ConfigService { | |
constructor(@Inject(configToken) private config: Config) { | |
console.log('new instance is created'); | |
} | |
getValue() { | |
return this.config; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { NgModule } from '@angular/core'; | |
import { ConfigModule } from '../shared/config.module'; | |
import { configToken } from '../shared/config.token'; | |
import { Config } from '../shared/config'; | |
import { DepartmentRoutingModule } from './department-routing.module'; | |
import { DepartmentComponent } from './department.component'; | |
export const configValue: Config = { | |
apiEndPoint: 'xyz.com', | |
timeout: 4000, | |
}; | |
@NgModule({ | |
declarations: [DepartmentComponent], | |
imports: [ | |
ConfigModule.forChild(), // π | |
CommonModule, | |
DepartmentRoutingModule, | |
], | |
providers: [ | |
{ | |
provide: configToken, useValue: configValue, | |
}, | |
], | |
}) | |
export class DepartmentModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject } from '@angular/core'; | |
import { configToken } from './config.token'; | |
import { Config } from './config'; | |
@Injectable() | |
export class ConfigService { | |
constructor(@Inject(configToken) private config: Config) { | |
console.log('new instance is created'); | |
} | |
getValue() { | |
return this.config; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { ConfigService } from './config.service'; | |
@NgModule({ | |
providers: [ | |
ConfigService, // π Always bundled, even if unused | |
], | |
}) | |
export class ConfigServiceModule { | |
static forChild(): ModuleWithProviders<ConfigModule> { | |
return { | |
ngModule: ConfigChildModule, | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject } from '@angular/core'; | |
import { configToken } from './config.token'; | |
import { Config } from './config'; | |
@Injectable() | |
export class ConfigService { | |
constructor(@Inject(configToken) private config: Config) { | |
console.log('new instance is created'); | |
} | |
getValue() { | |
return this.config; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { NgModule } from '@angular/core'; | |
import { ConfigServiceModule } from '../shared/config-service.module'; | |
import { configToken } from '../shared/config.token'; | |
import { Config } from '../shared/config'; | |
import { DepartmentRoutingModule } from './department-routing.module'; | |
import { DepartmentComponent } from './department.component'; | |
export const configValue: Config = { | |
apiEndPoint: 'xyz.com', | |
timeout: 4000, | |
}; | |
@NgModule({ | |
declarations: [DepartmentComponent], | |
imports: [ | |
ConfigServiceModule, // π | |
CommonModule, | |
DepartmentRoutingModule, | |
], | |
providers: [ | |
{ | |
provide: configToken, useValue: configValue, | |
}, | |
], | |
}) | |
export class DepartmentModule { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment