前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Angular2 路由传值

Angular2 路由传值

作者头像
用户1437675
发布2018-08-20 11:06:14
7590
发布2018-08-20 11:06:14
举报
文章被收录于专栏:Angular&服务Angular&服务

在接收值得组件里面导入ActivatedRoute

路由设置页面传参

代码语言:javascript
复制
{ path: 'view/:mid' , component: ViewComponent},

父级页面路由跳转的实现

代码语言:javascript
复制
<div [routerLink]="['/email/view',mail.id]">页面跳转传值</div>

子页面的Component通过下面的方法可以获取到父页面路由传过来的参数<b>mail.id</b>

代码语言:javascript
复制
//

import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";

@Component({
  selector: 'app-view',
  templateUrl: './view.component.html',
  styleUrls: ['./view.component.scss']
})
export class ViewComponent implements OnInit {

  constructor(public route: ActivatedRoute) {

        //通过这种形式来接收父级页面传过来的值
        this.route.params.subscribe(data=>console.log(data.mid))

        //或者通过
        this.route.params['value']['mid']
   }

  ngOnInit() {
  }

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.05.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档