當我使用按鈕時,我有一個可以作業的角度頁面。它正確地寫入了頁面標題。不幸的是,當使用重新加載按鈕重新加載頁面時,標題不會被重寫。這是html頁面的一部分:
標題部分的一部分:
<div class="alternate-theme" color="primary" style="height:30px;">
<span *ngIf="titleSite$ | async as title" class="center"> {{ title }} </span>
</div>
<mat-menu #menu="matMenu" [overlapTrigger]="false">
<button mat-menu-item (click)="navigateMenu('home')">
<mat-icon color="accent">home</mat-icon>
<span>Home page</span>
</button>
</mat-menu>
.ts 檔案的一部分:
export class TopMenuComponent implements OnInit {
public titleSite$: Observable<string>;
}
navigateMenu(tag) {
this.titleSite$ = this.translate.stream('Sitetitle0'); // Default title
this.initialTag$ = tag;
if (tag === "home") {
this.titleSite$ = this.translate.stream('Sitetitle1');
this.router.navigate(["/"]);
}
因此,當單擊按鈕時,會寫入正確的標題。但如果我重新加載頁面,它是默認標題。
一切正常,除非有人點擊重新加載。
我怎樣才能強制使用正確的標題,?之前在選單中單擊的那個。
謝謝
uj5u.com熱心網友回復:
每次您點擊重繪 時,您都會破壞變數,因此當頁面加載時,初始值將始終是默認標題。
可能的解決方案:
- 使用本地/會話存盤來保存有關活動標題的資訊,并在初始化時從那里讀取值。如果它不 ecist 那么它是默認標題。
- 將其存盤在服務器/外部某處
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/450787.html
