第一种:
<a [routerLink]="['/product']" [queryParams]="{id: 1}">商品详情</a>
第一种接收参数:
export class ProductComponent implements OnInit { 

  private productId: number; 
  constructor(private routeInfo: ActivatedRoute) {
   }
  ngOnInit() {
    this.productId = this.routeInfo.snapshot.queryParams["id"];
  }
} <p> product works! </p>
商品Id{{productId}}
第二种:
const routes: Routes = [
{
path:'',
component: HomeComponent
},
{
path: 'product/:id',
component: ProductComponent
}
,
{
path: '**',
component: Code404Component
}
];
<a [routerLink]="['/product',1]">商品详情</a>
第二种接收参数:
export class ProductComponent implements OnInit { private productId: number; constructor(private routeInfo: ActivatedRoute) { } ngOnInit() {
this.productId = this.routeInfo.snapshot.params["id"];
} }

参数订阅:

  ngOnInit() {
this.routeInfo.params.subscribe((params: Params)=> this.productId=params["id"]);
//this.productId = this.routeInfo.snapshot.params["id"];
}

参数快照:

  ngOnInit() {
//this.routeInfo.params.subscribe((params: Params)=> this.productId=params["id"]);
this.productId = this.routeInfo.snapshot.params["id"];
}

angular 路由传参的更多相关文章

  1. angular路由传参和获取路由参数的方法

    1.首先是需要导入的模块 import { Router } from "@angular/router";//路由传参用到 import{ActivatedRoute,Param ...

  2. 8.MVC框架开发(URL路由配置和URL路由传参空值处理)

    1.ASP.NET和MVC的路由请求处理 1)ASP.NET的处理 请求---------响应请求(HttpModule)--------处理请求(HttpHandler)--------把请求的资源 ...

  3. vue链接传参与路由传参

    1.链接传参: 例如:链接是:http://localhost:3333/#/index?id=001 我们要获取参数:console.log(this.$route.query.id):即可 2.路 ...

  4. vue路由传参的三种方式区别(params,query)

    最近在做一个项目涉及到列表到详情页的参数的传递,网上搜索一下路由传参,结合自己的写法找到一种适合自己的,不过也对三种写法都有了了解,在此记录一下 <ul class="table_in ...

  5. react router @4 和 vue路由 详解(六)vue怎么通过路由传参?

    完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 8.vue怎么通过路由传参? a.通配符传参数 //在定义路由的时候 { path: ' ...

  6. react router @4 和 vue路由 详解(五)react怎么通过路由传参

    完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 7.react怎么通过路由传参? a.通配符传参(刷新页面数据不丢失) //在定义路由的 ...

  7. vue动态路由配置,vue路由传参

    动态路由: 当我们很多个页面或者组件都要被很多次重复利用的时候,我们的路由都指向同一个组件,这时候从不同组件进入一个"共用"的组件,并且还要传参数,渲染不同的数据 这就要用到动态路 ...

  8. vue 路由传参

      mode:路由的形式 用的哪种路由 1.hash 路由 会带#号的哈希值 默认是hash路由   2.history路由 不会带#的     单页面开发首屏加载慢怎么解决?单页面开发首屏加载白屏怎 ...

  9. vue父子组件路由传参的方式

    一.get方式(url传参): 1.动态路由传参: 父组件: selectItem (item) { this.$router.push({ path: `/recommend/${item.id}` ...

随机推荐

  1. Linux:Linux 常用命令讲解(软件、硬件、文件)

    一.Linux 常用命令 所有的命令操作都是在服务器上进行的 自学参考:菜鸟 Linux man + 命令:查看命令的文档: 命令  +  --usage:查看命令的文档: 命令  +  --help ...

  2. java输出数组中出现的次数最多的那个及次数

    总结:理解每一个定义的变量 package com.aini; //一组数据,要求统计出最大值出现了多少次 public class Xd { public static void main(Stri ...

  3. oracle数据库查询题目!!!!!我的最爱

    使用scott/tiger用户下的emp表和dept表完成下列练习,表的结构说明如下 emp员工表(empno员工号/ename员工姓名/job工作/mgr上级编号/hiredate受雇日期/sal薪 ...

  4. PL/SQL 训练08--触发器

    --什么是触发器呢?--一触即发,某个事件发生时,执行的程序块?--数据库触发器是一个当数据库发生某种事件时作为对这个事件的响应而执行的一个被命名的程序单元 --适合场景--对表的修改做验证--数据库 ...

  5. Unity3D Demo

    之前在Unity讨论Q群里总是有不少同学求项目资源和源码神马的,其实这种资源在官网很多,而且都比较规范和专业,很有参考价值,链接:https://www.assetstore.unity3d.com/ ...

  6. spring+hibernate ---含AOP--事务--laobai

    biz包: package com.etc.biz; import java.util.List; import org.springframework.orm.hibernate3.support. ...

  7. Lambda中的常用sql方法

    1.Groupby 对集合进行分组,如: var dllList = _menuMan.Load(c => c.TXT_ASSEMBLYNAME != null).GroupBy(c=>c ...

  8. 分布式爬虫搭建系列 之二-----神器PyCharm的安装

    这里我们使用PyCharm作为开发工具,以下过程摘抄于:http://blog.csdn.net/qq_29883591/article/details/52664478  作者:陌上行走 Pytho ...

  9. numpy的一些用法

    安装numpy windows安装pip即可,具体方法参考pip官网 http://pip-cn.readthedocs.io/en/latest/installing.html 安装方法:pip i ...

  10. error: undefined reference to 'av_register_all()'

    cygwin下ndk编译工程中使用ffmpeg时出现的错误:“error: undefined reference to 'av_register_all()'” 使用ffmpeg的源文件是  *.c ...