【发布时间】:2021-08-04 12:58:54
【问题描述】:
我在我的 Angular PWA 应用程序中创建了一个示例闪屏组件。我只想在应用程序启动时显示一次启动画面。现在它显示在应用程序内任何页面上的每次刷新时,包括我的应用程序的启动。
如何在每次刷新时停止加载启动画面?
应用组件:-
<app-splash-screen></app-splash-screen>
<router-outlet></router-outlet>
闪屏组件:-
windowWidth : string | any | number;
showSplash: boolean = true;
constructor() { }
ngOnInit(): void {
setTimeout(()=> {
this.windowWidth = +'-' * window.innerWidth + 'px';
setTimeout(()=> {
this.showSplash = !this.showSplash
},500);
},2000);
}
闪屏 HTML:-
<div class="app-splash-screen" *ngIf="showSplash" [ngStyle]="{left: windowWidth}">
<div class="app-splash-screen-inner">
<div class="app-logo"><mat-icon>eco</mat-icon></div>
<div class="app=label">Welcome</div>
<div class="app-loader"></div>
</div>
</div>
【问题讨论】:
-
您可以存储在会话存储中。当页面加载最初将其存储在会话存储中,当您进行硬刷新时,从会话存储中获取值并相应地分配值。您可以在此处参考我的答案 - stackoverflow.com/a/68648003/6777125
-
@KrunalShah 我按照 Apporva 的建议进行存储(下面的答案),但我不知道如何在其他组件上使用该存储进行刷新?
标签: angular progressive-web-apps splash-screen