fix: sync theme select with value with theme service

This commit is contained in:
Sergey Andrievskiy 2019-06-25 21:38:39 +03:00
parent 77066ad20c
commit 28c29e088f
2 changed files with 12 additions and 3 deletions

View file

@ -5,7 +5,7 @@
</a>
<a class="logo" href="#" (click)="navigateHome()">ngx-<span>admin</span></a>
</div>
<nb-select [(selected)]="currentTheme" (selectedChange)="toggleTheme()" status="primary">
<nb-select [selected]="currentTheme" (selectedChange)="changeTheme($event)" status="primary">
<nb-option *ngFor="let theme of themes" [value]="theme.value"> {{ theme.name }}</nb-option>
</nb-select>
</div>

View file

@ -49,6 +49,8 @@ export class HeaderComponent implements OnInit, OnDestroy {
}
ngOnInit() {
this.currentTheme = this.themeService.currentTheme;
this.userService.getUsers()
.pipe(takeUntil(this.destroy$))
.subscribe((users: any) => this.user = users.nick);
@ -60,6 +62,13 @@ export class HeaderComponent implements OnInit, OnDestroy {
takeUntil(this.destroy$),
)
.subscribe((isLessThanXl: boolean) => this.userPictureOnly = isLessThanXl);
this.themeService.onThemeChange()
.pipe(
map(({ name }) => name),
takeUntil(this.destroy$),
)
.subscribe(themeName => this.currentTheme = themeName);
}
ngOnDestroy() {
@ -67,8 +76,8 @@ export class HeaderComponent implements OnInit, OnDestroy {
this.destroy$.complete();
}
toggleTheme() {
this.themeService.changeTheme(this.currentTheme);
changeTheme(themeName: string) {
this.themeService.changeTheme(themeName);
}
toggleSidebar(): boolean {