第一种:
<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. java代码实现点击鼠标从控制台输出信息

    总结:最难的就是当我们需要点击按钮时去实现某个功能-----------因为那个我没有理解透,是涉及整个程序的 package com.a.b; import javax.swing.*; impor ...

  2. java数组复制的简单方法(一)

    总结:主要是用a数组的长度等于b数组,然后a数组赋值给b数组,我不能想到这个办法,我还是不理解数组中length属性的含义 这里数组并没有正真复制过来,而是一个引用 package com.a; // ...

  3. java代码,输入n多个数,求其平均值,虽有重复,但是第二次,我就乱写了

    总结:对象调用方法,与在main 里直接输出没什么大的区别,少用方法, 乱搞++++ package com.c2; import java.util.Scanner; public class DD ...

  4. Kali下Ahmyth的使用

    项目地址:https://github.com/AhMyth/AhMyth-Android-RAT 下载后打开 安装nodejs,nodejs在官网下载,下载完后解压,切到bin目录下 设置全局 ro ...

  5. 10.solr学习速成之高亮显示

    Solr高亮显示的三种实现 高亮显示在搜索中使用的比较多,比较常用的有三种使用方式,如果要对某field做高亮显示,必须对该field设置stored=true .          第一种是普通的高 ...

  6. 「小程序JAVA实战」微信开发者工具helloworld(三)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-03/ 第一个小程序demo的运行,首选需要去使用开发工具 开发工具下载安装 https://mp. ...

  7. Delphi IOS 蓝牙锁屏后台运行

    Delphi IOS 后台运行 同样的程序,编译成android,锁屏后继续运行正常,蓝牙通讯正常,但在IOS下锁屏后程序的蓝牙就中断通讯了? IOS的机制就是这样,锁屏就关闭了. 音乐播放器是怎么做 ...

  8. 【知识结构】最强Web认证知识体系

    花了些时间总结了下Web认证,以及各种方式的利弊和使用,后续后继续更新.文章转载请注明出处:https://www.cnblogs.com/pengdai/p/9144843.html -----20 ...

  9. OSGI 模块化

    推荐教程:https://course.tianmaying.com/osgi-toturial+osgi-concept#15

  10. asp:GridView控件的使用

    使用asp:GridView显示一个统计的表格 cs样式: <style>        table.gridview_m        {            border-colla ...