[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 ...
随机推荐
- JavaScript 性能优化 --By Google V8 Team Manager
原文:https://developers.google.com/v8/?hl=zh-CN Be Prepared before writing code[9:35] Understand how V ...
- 【LeetCode】12 & 13 - Integer to Roman & Roman to Integer
12 - Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be wit ...
- Scrum之Sprint会议
Scrum的项目过程有一系列的Sprint组成. Sprint的长度一般控制在2-4周. 通过固定的周期保持良好的节奏. 产品的设计.开发.测试都在Sprint期间完成. Sprint结束时交付可以工 ...
- TopFreeTheme精选免费模板【20130703】
今天我们给大家分享13个最新的主题模板,5款WordPress主题,5款Joomla模板,3款OpenCart主题. BowThemes – BT Folio v1.0 Template for Jo ...
- win7启动出现蓝屏STOP: 0X0000007B
解决方法:开机进BIOS,更改Interface Combination,即硬盘的接口种类,由默认的RAID改成了AHCI,保存,重启,一切正常. 事件过程: 今天开机进入win7,在start wi ...
- 使用Java进行MD5加密
使用Java自带的MessageDigest类可以轻松实现MD5加密,只不过加密后得到的是byte数组,我们需要将其转换为16进制的字符. 代码如下: package com.stepsoft.tes ...
- JS获得月最后一天和js得到一个月最大天数
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>标题页</title ...
- 第三百零八至三百二十天 how can I 坚持
十三天..2月4号至2月16号,好快,假期还没开始就结束了.一一回忆下. 2月4号,腊月二十六,最后一天上班,没多大事,好像是玩了一天,东月回家,貌似路上好折腾,晚上D401,和她聊了一路,也聊了好多 ...
- 2d网络游戏的延迟补偿(Lag compensation with networked 2D games)
http://gamedev.stackexchange.com/questions/6645/lag-compensation-with-networked-2d-games ——————————— ...
- 什么是ADB
ADB, Android Debug Bridge, 是一个client-server程序,可以用来和安卓设备交流 Client: 用来发送命令的,client运行在开发机器上(电脑cmd, adb ...