Навигация не обновляется после изменения значения (угловой)Html

Программисты Html
Anonymous
Навигация не обновляется после изменения значения (угловой)

Сообщение Anonymous »

В настоящее время я работаю над своим первым угловым проектом и сталкиваюсь с проблемами с обновлением моего выпадающего меню HTML в заголовке, когда пользователь входит в систему. К сожалению, оно не функционирует, как ожидалось. /> Прямо сейчас он показывает только «логин» в раскрывающемся меню и не обновляется при входе в систему. Тем не менее, подписка в app.component.ts только обновляет состояние/значение подписанного наблюдаемого в начале, а не снова, когда пользователь входит в систему и изменяется значение. Выпадающее меню в App.component. Моя наблюдаемая переменная isuserLoggedin $ находится в логин-автоенсии .service. < /P>
Вот мой заголовок с раскрывающимся меню: < /p>

Код: Выделить всё

Dropdown
[i][/i]


Login
Details
Logout


< /code>
app.component.ts: < /p>
export class AppComponent implements OnInit {
title = 'auto-kino';
isLoggedIn: boolean = false;

constructor(private router: Router, private authService: LoginAuthenticationService) { }

ngOnInit() {
this.authService.isUserLoggedIn$.subscribe(loggedIn => {
this.isLoggedIn = loggedIn;
});
}
}
< /code>
login componenent.ts < /p>
  login(): void {
this.isFormSubmittedLogin = true;

if (this.userForm.invalid) {
return;
}

const { mail, passwort } = this.userForm.value;

this.loginautService.login(mail, passwort).subscribe(response => {
if (response.success) {
console.log("Login erfolgreich");
this.router.navigate(['/kundenkonto']);
} else {
this.errorMessageLogin = response.message;
console.log("Login fehlgeschlagen");
}
});
}
< /code>
login-authentication.service < /p>
export class LoginAuthenticationService {
private isUserLoggedInSubject = new BehaviorSubject(false);
isUserLoggedIn$ = this.isUserLoggedInSubject.asObservable();

public currentUser: any = {};

constructor(private http: HttpClient) { }

login(mail: string, passwort: string): Observable {
return new Observable(observer => {
this.http.post('http://127.0.0.1:8080/loginaut', { mail, passwort }).subscribe(
(response: any) => {
if (response.success) {
this.isUserLoggedInSubject.next(true);
this.currentUser = response.user;
localStorage.setItem('isUserLoggedIn', this.isUserLoggedInSubject ? "true" : "false");
localStorage.setItem('user', JSON.stringify(this.currentUser));
observer.next(response);
} else {
observer.next(response);
}
observer.complete();
},
(error) => {
observer.error(error);
observer.complete();
}
);
});
}
Я попытался настроить настройку на основе предложений из этого поста, но моя структура кода была/немного отличается, поэтому я не мог его копировать 1: 1. Кроме того, асинхрон не сработала. Я уже пробовал это. :)

Подробнее здесь: https://stackoverflow.com/questions/786 ... ed-angular

Вернуться в «Html»