[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. Params on the ActivatedRoute are provided as streams, so you can easily map the param you want off of the stream and display it in your template.
For example we have a HerosComonent, and inside HerosComponent, we will have multi HeroComponent:
heros.component.html:
<ul>
<li>
<a [routerLink]="'1'"
routerLinkActive="active"
[routerLinkActiveOptions]="{exact: true}">Hero 1</a>
</li>
</ul>
heros.routers.ts:
import {HerosComponent} from "./heros.component";
import {RouterModule} from "@angular/router";
import {HeroComponent} from "./hero/hero.component";
const routes = [
{path: '', component: HerosComponent},
{path: ':id', component: HeroComponent},
];
export default RouterModule.forChild(routes)
hero.component.ts:
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";
@Component({
selector: 'app-hero',
templateUrl: 'hero.component.html',
styleUrls: ['hero.component.css']
})
export class HeroComponent implements OnInit {
id;
constructor(private router: ActivatedRoute) {
this.id = router.params.map((p:any) => p.id);
}
ngOnInit() {
}
}
[Angular2 Router] Use Params from Angular 2 Routes Inside of Components的更多相关文章
- [Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive
You can easily show the user which route they are on using Angular 2’s routerLinkActive. Whenever a ...
- [Angular2 Router] Resolving route data in Angular 2
From Article: RESOLVING ROUTE DATA IN ANGULAR 2 Github If you know Anuglar UI router, you must know ...
- [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 ...
- [Angular2 Router] Build Angular 2 Navigation with routerLink
Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...
- [Angular2 Router] Optional Route Query Parameters - The queryParams Directive and the Query Parameters Observable
In this tutorial we are going to learn how to use the Angular 2 router to pass optional query parame ...
- [Angular2 Router] Index router
Index router as default router. import {RouterModule} from "@angular/router"; import {NotF ...
- [Angular2 Router] Using snapshot in Router
In the application, we have heros list, when click each hero, will redirect to hero detail view. Tha ...
- [Angular2 Router] Setup page title with Router events
Article import 'rxjs/add/operator/filter'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator ...
- vue router & query params
vue router & query params vue router get params from url https://zzk.cnblogs.com/my/s/blogpost-p ...
随机推荐
- EF Code First学习笔记
EF Code First学习笔记 初识Code First EF Code First 学习笔记:约定配置 Entity Framework 复杂类型 Entity Framework 数据生成选项 ...
- bzoj 3594 [Scoi2014]方伯伯的玉米田(DP+二维BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3594 [题意] 给定一个n个数的序列,有K次将一个区间内的数加1的机会,问最长不下降子 ...
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法----细节决定成败 (sort用法)
C++中cin.cin.get().cin.getline().getline().gets()等函数的用法 学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有 ...
- SQL存儲過程的調試方法
1.在vs2010调试存储过程步骤如下:(要點:連接登陸賬號的權限必須是管理員,才能單步調試,否則只能直接執行存儲過程:[因此,此方式適合數據庫和vs裝在同一台電腦上]) 1.1首先,打开vs,点击 ...
- linux3.0.4编译LDD中的scull全过程
按照惯例,我是应该先写一些本章的收获的,不过太晚了. 在看完第三章之后开始编译,错误一堆,几乎崩溃,幸亏经过不断的百度,总算解决了问题,我发现 我遇到问题比较多,算是集中七个龙珠了吧,感谢先行的大神们 ...
- Camel In Action 阅读笔记 第一章 认识Camel 1.1 Camel 介绍
1.1 Camel 介绍 Camel 是一个为了您的项目集成变得高效有趣的集成框架,Camel 项目在2007年初开始的,相对来说它还比较年轻,但它已然是一个非常成熟的开源项目,它所使用的是Apach ...
- LeetCode(2) - Add Two Numbers
一道比较基本的LinkedList的题目.题目要求是这样,现在有两个LinkedList,(2 -> 4 -> 3)和(5 -> 6 -> 4),然后从头开始,把每个node ...
- NServiceBus-容器
NServiceBus自动注册以及用户实现其所有组件处理程序和传奇,这样所有实例化模式和连接在默认情况下都是正确的,没有错误. NServiceBus在容器构建(目前Autofac的ilmerge版本 ...
- IDE Plug
IDE Plug 使用 cnpack提供的IDE External Wizard Management 管理插件.添加插件.删除插件 Cnpack D:\Program Files (x86)\CnP ...
- Objective-C 学习笔记(1)
文件描述: .h 类的声明文件,用户声明变量.函数(方法) .m 类的实现文件,用户实现.h中的函数(方法) 类的声明使用关键字 @interface.@end 类的实现使用关键字@implement ...