Files
mina-sidor-fa-web/apps/dafa-web/src/app/app.component.ts
2021-03-17 13:53:47 +01:00

35 lines
1010 B
TypeScript

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { User } from '@dafa-models/user.model';
import { filter } from 'rxjs/operators';
import { UnsubscribeDirective } from './directives/unsubscribe.directive';
@Component({
selector: 'dafa-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent extends UnsubscribeDirective {
path = '';
user: User = {
id: 'Fake user',
};
constructor(private router: Router) {
super();
super.unsubscribeOnDestroy(
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => {
const url = this.router.url;
this.path = url.split('/')[1].split('?')[0] || '';
})
);
}
get appClass(): string {
let defaultClass = `dafa dafa--${this.path.length ? this.path : 'home'}`;
return defaultClass;
}
}