### File

`projects/app-base-library/src/lib/angular/services/config.service.ts`

### Index

###### Properties

- Public services

###### Methods

- initialize
- initRouter
- loadTranslation

### Constructor

`constructor()`
Defined in projects/app-base-library/src/lib/angular/services/config.service.ts:5

### Methods

initialize
`initialize(options: )`
Defined in projects/app-base-library/src/lib/angular/services/config.service.ts:16

Parameters :

Name | Optional
options | no

Returns : `any`

initRouter
`initRouter(router: , component: )`
Defined in projects/app-base-library/src/lib/angular/services/config.service.ts:45

Parameters :

Name | Optional
router | no
component | no

Returns : `void`

loadTranslation
`loadTranslation(language: string, translateService: any)`
Defined in projects/app-base-library/src/lib/angular/services/config.service.ts:104

Parameters :

Name | Type | Optional
language | `string` | no
translateService | `any` | no

Returns : `any`

### Properties

Public services
`services: `any``
Type : `any`
Default value : `{ appService: undefined, translateService: undefined, }`
Defined in projects/app-base-library/src/lib/angular/services/config.service.ts:11

    import {Config} from '../../shared/config';
    import {Injectable} from '@angular/core';

    @Injectable()
    export class ConfigService extends Config {

        constructor() {
            super();
        }

        public services: any = {
            appService: undefined,
            translateService: undefined,
        };

        initialize(options) {
            const self = this;
            return new Promise(function (resolve, reject) {
                if(options.config) {
                    self.add(options.config);
                }
                self.fetch(options.settingsFile,true).then((newConfig) => {
                    self.setLocalSettings(self.get('id'), self.all());
                    self.set('ready', true);
                    resolve(self.all());
                    // todo:
                    // if(self.settings.xdomain){
                    //   self.initXdomain(res.xdomain)
                    // }
                    // fixme: deprecate - loads 2 times
                    // if (options.translateService && self.get('language')) {
                    //     self.loadTranslation(self.get('language'), options.translateService).then(() => {
                    //         self.set('ready', true);
                    //         resolve(self.all());
                    //     });
                    // } else {
                    //     self.set('ready', true);
                    //     resolve(self.all());
                    // }
                });
            });

        }

        initRouter(router, component) {
            router.events.subscribe( (event) => {
                let classes = '';
                let url: string;
                if (event.urlAfterRedirects && typeof event.urlAfterRedirects === 'string') {
                    url = event.urlAfterRedirects;
                    const urlParts = url.split('/');
                    urlParts.forEach((part) => {
                        if (part.match(';')) {
                            // has queryParams
                        }
                        classes += (part + ' ');
                    });
                }
                classes = classes.substring(1);
                classes = classes.substring(0, classes.length - 1);
                if (classes === '') {
                    classes = 'route-frontpage';
                }
                // set router classes on body tag
                document.querySelector('body').className = classes;
                document.querySelector('body').id = url;
            });
            //
            if (component.routes.length) {
                let routerMenu = [];
                component.routes.forEach((route) => {
                    if (!route.data) {
                        route.data = {};
                    }
                    // set router translations
                    if (component.translateService) {
                        if (route.data.title && route.data.title !== '') {
                            route.data.title = component.translateService.instant(route.data.title);
                        } else {
                            if (route.path !== '') {
                                route.data.title = component.translateService.instant(route.path);
                            }
                            if (route.path === '') {
                                route.data.title = component.translateService.instant('HOME');
                            }
                        }
                    }
                    // todo: deprecate + use url
                    route.href = route.path;
                    routerMenu.push(route);
                    // routerMenu.push({title: route.data.title, path: route.path, data: route.data, href: route.path});
                });
                // define routerMenu in config
                if (component.config) {
                    if (!component.config.get('menus')) {
                        component.config.set('menus', {});
                    }
                    let menus = component.config.get('menus');
                    menus['routerMenu'] = routerMenu;
                }
            }
        }

        loadTranslation(language: string, translateService: any) {
            const self = this;
            return new Promise(function (resolve, reject) {
                translateService.setDefaultLang(language);
                translateService.getTranslation(language).subscribe(function (res) {
                    resolve();
                });
            });
        }

    }

# results matching ""

# No results matching ""