Last active
June 14, 2023 08:42
-
-
Save nartc/a7f19cc6e42339dd872a6b45da81113e 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
@NgModule({ | |
imports: [OAuthModule.forRoot({...})] // <-- how to use the configuration.json here | |
}) | |
export class AppModule { | |
constructor(@Inject(AppConfig) private readonly appConfig: AppConfiguration) {} // I can inject | |
} |
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
{ | |
"apiBaseUrl": "https://localhost:5301" | |
} |
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
export interface AppConfiguration { | |
apiBaseUrl: string; | |
} | |
export const AppConfig = new InjectionToken<AppConfiguration>('@@appConfiguration'); |
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
(async () => { | |
try { | |
const config: AppConfiguration = await fetch('assets/configuration.json').then(res => res.json()); | |
if (config.production) { | |
console.log('Running in production mode'); | |
enableProdMode(); | |
} | |
platformBrowserDynamic([ | |
{ provide: AppConfig, useValue: config } | |
]).bootstrapModule(AppModule) | |
.catch(err => console.error(err)); | |
} catch (e) { | |
console.error('Error initializing', e); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Mr. Chau,
I tested by creating a middleware module with
forRoot
strategy and declaring a static function that returns 3rd-party modules. UsingforRoot
is new to me so can you help me take a look at my idea? I applied and ran with Nx Library inlibs
usingTransloco.forRoot( { prodMode }
getting fromenvironment.ts
inapps
folder. Personally, I think it's similar to your gist. By the way, I sent a message to your FB Messenger, please help me whenever you feel free.