[Angular] N things you might don't know about Angular Route
Prevent Partail Page display: By using Resolver:
@Injectable()
export class MovieResolver implements Resolve<IMovie> { constructor(private movieService: MovieService) { } resolve(route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<IMovie> {
const id = route.paramMap.get('id');
return this.movieService.getMovie(+id);
}
}
providers: [
MovieService,
MovieResolver
]
{
path: 'movies/:id',
resolve: { movie: MovieResolver },
component: MovieDetailComponent
},
ngOnInit(): void {
this.movie = this.route.snapshot.data['movie'];
}
Display Loading spinner when switching page:
constructor(private router: Router) {
router.events.subscribe((routerEvent: Event) => {
this.checkRouterEvent(routerEvent);
});
} checkRouterEvent(routerEvent: Event): void {
if (routerEvent instanceof NavigationStart) {
this.loading = true;
} if (routerEvent instanceof NavigationEnd ||
routerEvent instanceof NavigationCancel ||
routerEvent instanceof NavigationError) {
this.loading = false;
}
}
<span class="glyphicon glyphicon-refresh glyphicon-spin spinner"
*ngIf="loading"></span>
<router-outlet></router-outlet>
Enable route debugging:
RouterModule.forRoot([
{
path: '', component: ShellComponent,
children: [
{ path: 'welcome', component: WelcomeComponent },
{ path: 'movies', component: MovieListComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' }
]
},
{ path: 'login', component: LoginComponent },
{ path: '**', component: PageNotFoundComponent }
], { enableTracing: true })
[Angular] N things you might don't know about Angular Route的更多相关文章
- [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 la ...
- Angular 1 深度解析:脏数据检查与 angular 性能优化
TL;DR 脏检查是一种模型到视图的数据映射机制,由 $apply 或 $digest 触发. 脏检查的范围是整个页面,不受区域或组件划分影响 使用尽量简单的绑定表达式提升脏检查执行速度 尽量减少页面 ...
- angular源码分析:injector.js文件分析——angular中的依赖注入式如何实现的(续)
昨天晚上写完angular源码分析:angular中jqLite的实现--你可以丢掉jQuery了,给今天定了一个题angular源码分析:injector.js文件,以及angular的加载流程,但 ...
- 【Angular专题】——(2)【译】Angular中的ForwardRef
原文地址:https://blog.thoughtram.io/angular/2015/09/03/forward-references-in-angular-2.html 作者:Christoph ...
- [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 ...
- [Angular2 Router] Configure Auxiliary Routes in the Angular 2 Router - What is the Difference Towards a Primary Route?
In this tutorial we are going to learn how we can can configure redirects in the angular 2 router co ...
- angular 子路由跳转出现Navigation triggered outside Angular zone, did you forget to call ‘ngZone.run() 的问题修复
angular 路由功能非常强大,同时angular的路由也非常脆弱,非常容易出现错误. 那么在我们遇到异常时,首先要做的是什么? 第一步:检查代码,对比官方文档,发现代码中不一致的地方进行改正. 第 ...
- [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’ ...
- Angular05 angular架构、搭建angular开发环境、组件必备三要素、angular启动过程
1 angular架构 1.1 组件:是angular应用的基本构建模块,可以理解为一段带有业务逻辑和数据的HTML 1.2 服务:用来封装可重用的业务逻辑 1.3 指令:允许你想HTML元素添加自定 ...
随机推荐
- Squares(枚举+set 查找)
http://poj.org/problem?id=2002 题意:给出n组坐标,判断这些坐标能组成的正方形的个数. 思路:参考某大神的想法,先枚举两个点,然后利用公式表示出另外两个点,判断这两个点是 ...
- Hardwood Species(map)
http://poj.org/problem?id=2418 题意:给定一系列字符串,要求按字典序升序输出每个串,并输出每个串出现的百分比. 用map做的,交c++A了,G++ WA..so sad. ...
- 应用JavaScript搭建一个简易页面图片无缝滚动效果
页面图片无缝滚动JavaScript原理:移动的区块包含图片内容,区块相对父级元素进行定位脱离文档流.再令区块的left值每隔固定的时间进行等量减少(或增大)从而实现区块的匀速运动.由于每次间隔移动的 ...
- python3+request接口自动化框架中自动发送邮件
在上一篇中的自动化框架中没有放上自动发送测试结果到邮箱的功能,在这篇文章中在补一下,哈哈 1.上一篇的代码就不在一一介绍了,本篇只介绍发送邮件的功能代码 2.在public common 文件夹中创建 ...
- 关于offer对比
前天签了三方,在签约前的几个小时,还在纠结到底该accept哪个offer,相信很多同学都会遇到这个问题,就由此展开去吧. 关于offer的选择,无外乎以下几个考察点:1.个人发展:2.地域:3.薪资 ...
- POJ 3630 trie树
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26559 Accepted: 8000 Descripti ...
- [转]line-height1.5和line-height:150%的区别
line-height1.5和line-height:150%的区别 一.区别 区别体现在子元素继承时,如下: 父元素设置line-height:1.5会直接继承给子元素,子元素根据自己的font ...
- SDOI 2018 round2游记
Day 0 早上起来从北京到济南 住宿环境不错 不过比赛环境怎么这么low啊 而且我在最偏僻的考场中最偏僻的角落里 身边居然是个妹子?! Day1 7:40到的考试地点 发现诸位大佬已经打完板子了or ...
- Spring boot -环境搭建 ,初步接触(1)
1. Eclipse 创建 maven project 项目目录如下: 2. pom.xml 配置文件 <project xmlns="http://maven.apache.or ...
- Android_方向传感器
Android方向传感器小案例,主要代码如下: package com.hb.direction; import android.app.Activity; import android.conten ...