angular 路由传参
第一种:
<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 路由传参的更多相关文章
- angular路由传参和获取路由参数的方法
1.首先是需要导入的模块 import { Router } from "@angular/router";//路由传参用到 import{ActivatedRoute,Param ...
- 8.MVC框架开发(URL路由配置和URL路由传参空值处理)
1.ASP.NET和MVC的路由请求处理 1)ASP.NET的处理 请求---------响应请求(HttpModule)--------处理请求(HttpHandler)--------把请求的资源 ...
- vue链接传参与路由传参
1.链接传参: 例如:链接是:http://localhost:3333/#/index?id=001 我们要获取参数:console.log(this.$route.query.id):即可 2.路 ...
- vue路由传参的三种方式区别(params,query)
最近在做一个项目涉及到列表到详情页的参数的传递,网上搜索一下路由传参,结合自己的写法找到一种适合自己的,不过也对三种写法都有了了解,在此记录一下 <ul class="table_in ...
- react router @4 和 vue路由 详解(六)vue怎么通过路由传参?
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 8.vue怎么通过路由传参? a.通配符传参数 //在定义路由的时候 { path: ' ...
- react router @4 和 vue路由 详解(五)react怎么通过路由传参
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 7.react怎么通过路由传参? a.通配符传参(刷新页面数据不丢失) //在定义路由的 ...
- vue动态路由配置,vue路由传参
动态路由: 当我们很多个页面或者组件都要被很多次重复利用的时候,我们的路由都指向同一个组件,这时候从不同组件进入一个"共用"的组件,并且还要传参数,渲染不同的数据 这就要用到动态路 ...
- vue 路由传参
mode:路由的形式 用的哪种路由 1.hash 路由 会带#号的哈希值 默认是hash路由 2.history路由 不会带#的 单页面开发首屏加载慢怎么解决?单页面开发首屏加载白屏怎 ...
- vue父子组件路由传参的方式
一.get方式(url传参): 1.动态路由传参: 父组件: selectItem (item) { this.$router.push({ path: `/recommend/${item.id}` ...
随机推荐
- mysql数据恢复 insert\update\delete 工具MyFlash
一.简介MyFlash是由美团点评公司技术工程部开发维护的一个回滚DML操作的工具.该工具通过解析v4版本的binlog,完成回滚操作.相对已有的回滚工具,其增加了更多的过滤选项,让回滚更加容易. 该 ...
- python开发模块基础:正则表达式
一,正则表达式 1.字符组:[0-9][a-z][A-Z] 在同一个位置可能出现的各种字符组成了一个字符组,在正则表达式中用[]表示字符分为很多类,比如数字.字母.标点等等.假如你现在要求一个位置&q ...
- springboot成神之——mybatis和mybatis-generator
项目结构 依赖 generator配置文件 properties配置 生成文件 使用Example 本文讲解如何在spring-boot中使用mybatis和mybatis-generator自动生成 ...
- transfrom-runtime文档
transfrom-runtime文档 babel只会默认对句法进行转换,而那些方法,api不会转换,要转就要使用polyfill和transform,这里介绍transform,关于polyfill ...
- Linux 学习笔记之 --- epoll 事件模型详解
epoll 主要采用对已就绪的 fd 进行轮询操作 一.epoll 触发方式 epoll支持 ET 和 LT 两种触发方式 ET(边缘触发):Nginx 就是采用 ET 触发方式,只支持 no-b ...
- LCD 调试总结
转自:http://blog.csdn.net/qikaibinglan/article/details/5630246 (1) 液晶显示模式 并行:MCU接口.RGB接口.Vysnc接口 串行:SP ...
- Objective-C 的 self 和 super 详解 (用简单程序说明问题)
在 Objective-C 中的类实现中经常看到这两个关键字 "self" 和 "super",以以前 oop 语言的经验,拿 c++ 为例,self 相当于 ...
- 在java中RandomAccessFile类的作用:对指定文件可以进行读写的操作
- IP地址分类和子网划分
IP地址: 地址范围 网络地址规律 子网掩码 私有地址 保留地址 A类地址:从1.0.0.0 到1 ...
- php安装memcache
php扩展memcache的作用是为了支持memcached数据库缓存服务器,下面是安装方法. 1.下载并解压memcache文件 1 2 3 wget -c http://pecl.php.net/ ...