Skip to content

Instantly share code, notes, and snippets.

@nartc
Last active June 14, 2023 08:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nartc/a7f19cc6e42339dd872a6b45da81113e to your computer and use it in GitHub Desktop.
Save nartc/a7f19cc6e42339dd872a6b45da81113e to your computer and use it in GitHub Desktop.
@NgModule({
imports: [OAuthModule.forRoot({...})] // <-- how to use the configuration.json here
})
export class AppModule {
constructor(@Inject(AppConfig) private readonly appConfig: AppConfiguration) {} // I can inject
}
{
"apiBaseUrl": "https://localhost:5301"
}
export interface AppConfiguration {
apiBaseUrl: string;
}
export const AppConfig = new InjectionToken<AppConfiguration>('@@appConfiguration');
(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);
}
})()
@thanhhoa214
Copy link

Is there any answer for

  imports: [OAuthModule.forRoot({...})] // <-- how to use the configuration.json here

I tried nx-workspace and get in stuck with the case:

  • I need import from environment.ts to config your gist above, so I choose to put core or shell (just naming) module under apps/ folder. It leads to another problem when I wanna import services from core module.

I was confused for more than a week & check Angular Spotify of @trungk18 but can't find any solution. Please help. Thanks in advance!

@thanhhoa214
Copy link

Hi Mr. Chau,
I tested by creating a middleware module with forRoot strategy and declaring a static function that returns 3rd-party modules. Using forRoot is new to me so can you help me take a look at my idea? I applied and ran with Nx Library in libs using Transloco.forRoot( { prodMode } getting from environment.ts in apps 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment