У меня проблема с моим app.component.html, я использую этот блок:
<router-outlet *ngIf="!accessGranted"></router-outlet>
<div *ngIf="accessGranted" class="wrapper">
<app-header></app-header>
<app-left-menu></app-left-menu>
<router-outlet></router-outlet>
<app-footer></app-footer>
<app-right-menu></app-right-menu>
</div>
Когда accessGranted
имеет значение false, я загружаю тему входа, когда accessGranted
это правдаЯ загружаю все с приборной панели.Хорошо, это прекрасно, работает, я ожидал.Но проблема в том ... как обновить переменную accessGranted
из службы?в настоящее время у меня есть это в app.component.ts:
app.component.ts
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ThemeService } from './services/theme.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
title = 'SmartliveWeb';
accessGranted: boolean;
constructor (private _themeService: ThemeService) {
this.accessGranted = _themeService.accessGranted;
}
}
theme.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ThemeService {
accessGranted = false;
constructor() {
}
}
Когда пользователь входит в приложение, я хочу изменить accessGranted
на true, чтобы изменить тему, но всегда оставаться в false.Можно ли применить изменения в app.component при изменении accessGranted
в службе?