2018-07-04 17:51:31 +02:00
|
|
|
import { Injector } from '@angular/core';
|
2018-06-19 16:55:50 +02:00
|
|
|
import { Title } from '@angular/platform-browser';
|
2018-07-04 17:51:31 +02:00
|
|
|
import { DataStoreService } from 'app/core/services/DS.service';
|
2018-06-19 16:55:50 +02:00
|
|
|
|
2018-07-04 17:51:31 +02:00
|
|
|
// provides functions that might be used by a lot of components
|
2018-06-19 16:55:50 +02:00
|
|
|
export abstract class BaseComponent {
|
2018-07-04 17:51:31 +02:00
|
|
|
protected injector: Injector;
|
|
|
|
protected dataStore: DataStoreService;
|
2018-06-19 16:55:50 +02:00
|
|
|
private titleSuffix = ' - OpenSlides 3';
|
|
|
|
|
2018-07-04 17:51:31 +02:00
|
|
|
constructor(protected titleService?: Title) {
|
|
|
|
// throws a warning even tho it is the new syntax. Ignored for now.
|
|
|
|
this.injector = Injector.create([{ provide: DataStoreService, useClass: DataStoreService, deps: [] }]);
|
|
|
|
}
|
2018-06-19 16:55:50 +02:00
|
|
|
|
|
|
|
setTitle(prefix: string) {
|
|
|
|
this.titleService.setTitle(prefix + this.titleSuffix);
|
|
|
|
}
|
2018-07-04 17:51:31 +02:00
|
|
|
|
|
|
|
// static injection of DataStore (ds) in all child instancces of BaseComponent
|
|
|
|
// use this.DS[...]
|
|
|
|
get DS(): DataStoreService {
|
|
|
|
if (this.dataStore == null) {
|
|
|
|
this.dataStore = this.injector.get(DataStoreService);
|
|
|
|
}
|
|
|
|
return this.dataStore;
|
|
|
|
}
|
2018-06-19 16:55:50 +02:00
|
|
|
}
|