【发布时间】:2019-03-19 05:37:45
【问题描述】:
我正在使用 Angular 6。
我的应用程序在加载组件之前需要几秒钟的时间,而这段时间用于加载资源和验证用户。
当这一切发生时,我的应用程序显示一个空白页。
我想用 preloader 替换那个丑陋的白色页面,该页面将在所有后台进程完成之前一直显示。
为此,我在 index.html 之内添加了一个 CSS 加载微调器
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My App</title>
<base href="/">
<!-- Fonts and icons -->
</head>
<body>
<app-root>
<!-- Pre-loading spinner -->
<!-- This code within the app-root will be wiped of once the child component is loaded -->
<!-- This code will not even be shown in the source code once the child component is loaded -->
<!-- We can put any code css/html/image/etc here -->
<style>
/** CSS here. Since it will be wiped totally, 'll not cause any impact to the core stylesheet.
</style>
Loading<span class="d">.</span><span class="d d-2">.</span><span class="d d-3">.</span>
</app-root>
</body>
</html>
这会显示一个类似的页面
但问题是这样的。第一个加载的组件是 app.component.html,它有以下内容
<router-outlet></router-outlet>
这进一步加载了另一个组件 admin-layout-component.html 的内容
<div class="wrapper">
<div class="sidebar" data-color="red">
<app-sidebar></app-sidebar>
</div>
<div class="main-panel">
<app-navbar></app-navbar>
<router-outlet></router-outlet>
<app-footer></app-footer>
</div>
</div>
一旦 app.component 被加载,来自 index.html 的微调器内容就会被移除并开始显示空白页面,直到 admin-layout 已加载。
我尝试在 app.component.html 的 router-outlet 中添加相同的样式代码,但是当组件加载时,内容与微调器一起添加并且微调器不会从其他页面中删除。
在加载仪表板页面之前,如何在 app.component.html 上显示微调器。
这是一个如何工作的视频:https://youtu.be/RSlTi0EQHm4
【问题讨论】: