You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.component.ts 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {Component, OnInit, TemplateRef, ViewChild} from '@angular/core';
  2. import {MediaChange, ObservableMedia} from '@angular/flex-layout';
  3. import {CgBusyDefaults} from 'angular-busy2';
  4. import {AppStateService} from './services/app-state.service';
  5. import {UiStateViewModel} from './view-models/ui/ui-state.view-model';
  6. import {Observable} from 'rxjs';
  7. import {Title} from '@angular/platform-browser';
  8. @Component({
  9. selector: 'app-root',
  10. templateUrl: './app.component.html',
  11. styleUrls: ['./app.component.css']
  12. })
  13. export class AppComponent implements OnInit {
  14. title = 'Site Status';
  15. @ViewChild('cgBusyTemplate')
  16. private cgBusyTemplate: TemplateRef<any>;
  17. public uiState$: Observable<UiStateViewModel>;
  18. constructor(private busyDefaults: CgBusyDefaults, private titleService: Title,
  19. media: ObservableMedia, appStateService: AppStateService) {
  20. media.subscribe((change: MediaChange) => {
  21. if (change.mqAlias === 'sm' || change.mqAlias === 'xs') {
  22. appStateService.setUiStateMobile();
  23. } else {
  24. appStateService.setUiStateDesktop();
  25. }
  26. });
  27. this.uiState$ = appStateService.onUiStateUpdated();
  28. this.uiState$.subscribe(this.onUiStateChange.bind(this));
  29. }
  30. onUiStateChange(state: UiStateViewModel) {
  31. this.titleService.setTitle(state.page.title);
  32. }
  33. ngOnInit() {
  34. this.busyDefaults.templateRef = this.cgBusyTemplate;
  35. }
  36. }