[Angular] Show a Loading Indicator for Lazy Routes in Angular
We can easily code split and lazy load a route in Angular. However when the user then clicks that lazy loaded route, it make some time to actually fetch and run the JavaScript bundle. In this lesson we'll see how we can implement a loading indicator for such lazy loaded routes.
<!-- app.component.thml --> <router-outlet>
<span class="loader" *ngIf="loading"></span>
</router-outlet>
import { Component } from '@angular/core';
import { Router, RouteConfigLoadStart, RouteConfigLoadEnd, RouterEvent } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
loading: boolean;
constructor(router: Router) {
this.loading = false;
router.events.subscribe(
(event: RouterEvent): void => {
if (event instanceof RouteConfigLoadStart) {
this.loading = true;
} else if (event instanceof RouteConfigLoadEnd) {
this.loading = false;
}
}
);
}
}
[Angular] Show a Loading Indicator for Lazy Routes in Angular的更多相关文章
- [Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe
The network may be unreliable and loading data may take time. Thus it is important to give the user ...
- Angular 1 深度解析:脏数据检查与 angular 性能优化
TL;DR 脏检查是一种模型到视图的数据映射机制,由 $apply 或 $digest 触发. 脏检查的范围是整个页面,不受区域或组件划分影响 使用尽量简单的绑定表达式提升脏检查执行速度 尽量减少页面 ...
- angular源码分析:injector.js文件分析——angular中的依赖注入式如何实现的(续)
昨天晚上写完angular源码分析:angular中jqLite的实现--你可以丢掉jQuery了,给今天定了一个题angular源码分析:injector.js文件,以及angular的加载流程,但 ...
- angular 子路由跳转出现Navigation triggered outside Angular zone, did you forget to call ‘ngZone.run() 的问题修复
angular 路由功能非常强大,同时angular的路由也非常脆弱,非常容易出现错误. 那么在我们遇到异常时,首先要做的是什么? 第一步:检查代码,对比官方文档,发现代码中不一致的地方进行改正. 第 ...
- 【Angular专题】——(2)【译】Angular中的ForwardRef
原文地址:https://blog.thoughtram.io/angular/2015/09/03/forward-references-in-angular-2.html 作者:Christoph ...
- [Angular] N things you might don't know about Angular Route
Prevent Partail Page display: By using Resolver: @Injectable() export class MovieResolver implements ...
- [Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular
By default the new Angular Http client (introduced in v4.3.1) uses JSON as the data format for commu ...
- [Angular] Create a custom validator for reactive forms in Angular
Also check: directive for form validation User input validation is a core part of creating proper HT ...
- [Angular 8] Calculate and Measure Performance budgets with the Angular CLI
Measuring is extremely important, without numbers we don’t know about potential problems and we don’ ...
随机推荐
- Python30之文件2(文件系统)
一.在python中对于文件系统的访问一般使用的是os模块.python是跨平台的,因此在使用os模块时,不需要关心是在什么系统下使用的 import os >>> os.listd ...
- vue导入css,js和放置html代码
使用场景:我是从网上找的html前端页面模板,导入找的模板中的css和js到vue中使用. 1.在main.js中全局导入css和js import '@/assets/css/main.css' i ...
- PAT(B) 1087 有多少不同的值(Java)规律
题目链接:1087 有多少不同的值 (20 point(s)) 题目描述 当自然数 n 依次取 1.2.3.--.N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取 ...
- AVR单片机教程——随机点亮LED
之前我们做的闪烁LED和流水灯,灯效都是循环的.这次我们来尝试一些不一样的——每一次随机选择一个LED并点亮. 要实现随机的效果,我们要用C语言标准库中的相关设施: #define RAND_MAX ...
- 立体像对空间前方交会-共线方程求解法(python实现)
一.原理 二.步骤 a.用各自像片的角元素计算出左右像片的旋转矩阵R1和R2. b.有同名像点列出共线方程. c.将方程写为未知数的线性方程形式,计算线性系数. d.写出误差方程,系数矩阵与常数项. ...
- Elastic Search快速上手(2):将数据存入ES
前言 在上手使用前,需要先了解一些基本的概念. 推荐 可以到 https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.htm ...
- 优秀的java 社区
并发编程网 - ifeve.com InfoQ - 促进软件开发领域知识与创新的传播开源中国 - 找到您想要的开源项目,分享和交流IBM developerWorks 中国 : IBM's resou ...
- IDEA使用技巧--将本地项目和git远程项目关联
之前开发没有从头儿搭建过新项目,都是从IDEA配置下项目的git地址,pull代码之后进行开发,提交.这次需要将本地新建的项目push到在git上同样是新建的空项目上去(git上的项目只有工程名和re ...
- CSS中@import url()
@import url( )总结: 1.import url( )机制是不同于link的,link是在加载页面前把CSS加载完毕,而@import url( )则是读取完文件后加载,所以会出现一开始没 ...
- iview的table中Tooltip的使用
这篇文章主要介绍了iview-admin中在table中使用Tooltip提示效果. 1. table中文字溢出隐藏,提示气泡展示所有信息 jLongText(item){ item.render = ...