[Angular2 Router] Using snapshot in Router
In the application, we have heros list, when click each hero, will redirect to hero detail view. That means, hero detail component will get inited everytime. Currently there is no option to navigate to bewteen two hero detail.
Currently, we use Observable way:
this.hero = this.router.params
.map((p:any) => p.id)
.switchMap( id => this.starwarService.getPersonDetail(id));
There is another none Observable way, this is more performence:
export class HeroComponent implements OnInit {
hero: Observable<any>;
constructor(private router: ActivatedRoute,
private starwarService: StarWarsService) {
}
ngOnInit() {
const heroId = this.router.snapshot.params['id'];
this.hero = this.starwarService.getPersonDetail(heroId);
}
}
snapshot only init when the component init, so it won't change. If you use Observable, it means that the variable might change. In our case, use snapshot is better.
[Angular2 Router] Using snapshot in Router的更多相关文章
- [Angular2 Router] Programmatic Router Navigation via the Router API - Relative And Absolute Router Navigation
In this tutorial we are going to learn how to navigate programmatically (or imperatively) by using t ...
- this.$router.go()和this.$router.push()的差别
1.this.$router.go(val) => 在history记录中前进或者后退val步,当val为0时刷新当前页面. 2.this.$router.push(path) => 在h ...
- 手撸Router,还要啥Router框架?react-router/vue-router躺一边去
有没有发现,在大家使用React/Vue的时候,总离不开一个小尾巴,到哪都得带着他,那就是react-router/vue-router,而基于它们的第三方框架又出现很多个性化约定和扩展,比如nuxt ...
- [Angular2 Router] Use Params from Angular 2 Routes Inside of Components
Angular 2’s ActivatedRoute allows you to get the details of the current route into your components. ...
- [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 ...
- [Angular2 Router] Auxiliary Routes bit by bit
Article Github Auxiliary Routes is is little bit hard to understand. Here is demo, link You can see ...
- react+redux教程(四)undo、devtools、router
上节课,我们介绍了一些es6的新语法:react+redux教程(三)reduce().filter().map().some().every()....展开属性 今天我们通过解读redux-undo ...
- Node.js -- Router模块中有一个param方法
这段时间一直有在看Express框架的API,最近刚看到Router,以下是我认为需要注意的地方: Router模块中有一个param方法,刚开始看得有点模糊,官网大概是这么描述的: 1 Map lo ...
- ZeroMQ(java)之Router/Dealer模式
本教程转自:http://blog.csdn.net/kobejayandy/article/details/20163527 在开始之前先把guid里面提到的几个ZeroMQ的特性列一下吧: (1) ...
随机推荐
- 俄罗斯方块游戏 --- java
俄罗斯方块游戏 如有疑问请查看:http://zh.wikipedia.org/zh-tw/%E4%BF%84%E7%BD%97%E6%96%AF%E6%96%B9%E5%9D%97 更多疑问请参考: ...
- int型长度
Ø 基本数据类型 C语言中只有4中基本数据类型——整型.浮点型.指针和聚合类型(如数组和结构等):所有其他类型都是从这4种基本类型的某种变化或组合派生而来. 一.整型家族 整型家族包括char.sh ...
- 解读Cardinality Estimation<基数估计>算法(第一部分:基本概念)
基数计数(cardinality counting)是实际应用中一种常见的计算场景,在数据分析.网络监控及数据库优化等领域都有相关需求.精确的基数计数算法由于种种原因,在面对大数据场景时往往力不从心, ...
- extjs 学习笔记(二)
EXTJS实用开发指南 1. 要使用ExtJS 框架的页面中一般包括下面几句: <link rel="stylesheet" type="text/css" ...
- [WebService]之DTD
文档类型定义(DTD)可定义合法的XML文档构建模块.它使用一系列合法的元素来定义文档的结构. DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. <?xml version=& ...
- Flex SDK包内文件夹内容说明
打开SDK目录,让我们看看SDK中都包含了哪些内容: ant包含Flex对Ant的支持库,JAR和Java源码都有,方便我们基于Ant完成对项目的构建 asdoc基于ASDOC我们可以很方便的生成代码 ...
- python添加windows域验证
1.安装python-ldap https://pypi.python.org/pypi/python-ldap/ 在 Ubuntu/Debian 下安装 python-ldap 模块: $ sudo ...
- bool?
public class GuestResponse { [Required(ErrorMessage = "Please enter your name")] public st ...
- Spring.Scheduling.Quartz的使用
最近因使用Spring.Net框架而接触.了解到其与Quartz.Net的集成,即Spring.Scheduling.Quartz模块. Spring通过对Quartz.Net的封装,采用了sprin ...
- CodeForces 534C Polycarpus' Dice (数学)
题意:第一行给两个数,n 和 A,n 表示有n 个骰子,A表示 n 个骰子掷出的数的和.第二行给出n个数,表示第n个骰子所能掷出的最大的数,这些骰子都有问题, 可能或多或少的掷不出几个数,输出n个骰子 ...