src/lib/eo-core.module.ts
Main module for connecting an app to an yuuvis® RAD backend. To use it just import int in your app module:
`
javascript
Main module for connecting an app to an yuuvis® RAD backend. To use it just import int in your app module:
@NgModule({
imports: [
EoCoreModule.forRoot(<config>)
], ...})
add the styles to your CLI project by adding node_modules/@enaio-sdk/core/main.css
to the styles section of your angular.json
or
use @import '~@eo-sdk/core/main.css';
in the main styles.scss.
EoCoreModule
can be initialized with a custom configuration: If it's not set, defaults apply.
{
main: EnaioConfig | string[], // main config object or paths to the config files (defaults to: ['assets/_default/config/main.json'])
translations: string[], // paths to folders where the translations reside (defaults to: ['assets/_default/i18n/'])
environment: {production: boolean} = {production: true},
// sets the HTTP 'withCredentials' flag for every backend call
withCredentials?: boolean = false
}
EoCoreModule
re-exports EoSharedModule, so you can use shared modules (for example translations) inside of your app. If you create your own modules that get imported in your app module, you need to import EoSharedModule there on your own. Just add import {EoSharedModule} from '@eo-sdk/core';
and you are ready to go. Everything else is handled by EoCoreModule
.
import { HTTP_INTERCEPTORS, HttpClient, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import {APP_INITIALIZER, ModuleWithProviders, NgModule, Optional, SkipSelf} from '@angular/core';
import {MissingTranslationHandler, TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {ToastrModule} from 'ngx-toastr';
import {CoreConfig} from './config/core-config';
import {CoreInit} from './config/core-init.service';
import {CORE_CONFIG, CUSTOM_CONFIG} from './config/core-init.tokens';
import {init_module} from './config/initialize-module';
import {EoxMissingTranslationHandler} from './config/missing-translation-handler';
import {EoxTranslateJsonLoader} from './config/translate-json-loader';
import {EoSharedModule} from './eo-core-shared.module';
import {AuthInterceptor} from './service/auth/auth-interceptor';
import {ConsoleLogService} from './service/logger/console-log.service';
import {Logger} from './service/logger/logger';
/**
* Main module for connecting an app to an yuuvis<sup>®</sup> RAD backend. To use it just import int in your app module:
*
* ```javascript
* @NgModule({
* imports: [
* EoCoreModule.forRoot(<config>)
* ], ...})
* ```
*
* add the styles to your CLI project by adding `node_modules/@enaio-sdk/core/main.css` to the styles section of your `angular.json` or
* use `@import '~@eo-sdk/core/main.css';` in the main styles.scss.
*
* ## config
* `EoCoreModule` can be initialized with a custom configuration: If it's not set, defaults apply.
*
* ```json
* {
* main: EnaioConfig | string[], // main config object or paths to the config files (defaults to: ['assets/_default/config/main.json'])
* translations: string[] // paths to folders where the translations reside (defaults to: ['assets/_default/i18n/'])
* }
* ```
*
* `EoCoreModule` re-exports EoSharedModule, so you can use shared modules (for example translations) inside of your app.
* If you create your own modules that get imported in your app module, you need to import EoSharedModule there on your own.
* Just add `import {EoSharedModule} from '@eo-sdk/core';` and you are ready to go. Everything else is
* handled by `EoCoreModule`.
*/
@NgModule({ exports: [EoSharedModule], imports: [TranslateModule.forRoot(),
/**
* [to use toastr without dependency of @angular/animations]{@link https://www.npmjs.com/package/ngx-toastr}
*/
ToastrModule.forRoot()], providers: [
{
/**
* provide a logging implementation for the current platform
*/
provide: Logger,
useClass: ConsoleLogService
},
provideHttpClient(withInterceptorsFromDi()),
] })
export class EoCoreModule {
static forRoot(config?: CoreConfig): ModuleWithProviders<EoCoreModule> {
return {
ngModule: EoCoreModule,
providers: [
CoreInit,
{provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true},
{provide: CUSTOM_CONFIG, useValue: config},
{provide: CORE_CONFIG, useClass: CoreConfig, deps: [CUSTOM_CONFIG]},
{provide: APP_INITIALIZER, useFactory: init_module, deps: [CoreInit], multi: true},
/**
* overriding translate modules defaults
* this works because providers are singletons
*/
{provide: TranslateLoader, useClass: EoxTranslateJsonLoader, deps: [HttpClient, CORE_CONFIG]},
{provide: MissingTranslationHandler, useClass: EoxMissingTranslationHandler}
]
};
}
/**
* @ignore
*/
constructor(@Optional() @SkipSelf() parentModule: EoCoreModule) {
if (parentModule) {
throw new Error(
'EoCoreModule is already loaded. Import it in the AppModule only');
}
}
}