Angular路由跳转时,如何传递信息
我们期望实现的场景:从product list Component点击产品名称超链接时,能跳转到product detail Component,显示选中的product的明细信息。
在product detail Component引入路由相关的library:
import { ActivatedRoute } from ‘@angular/router’;
导入product sample data:
在product detail Component里定义一个名为product的property,同时通过将import的ActivatedRoute添加到Component的构造函数的参数里,实现注入的目的:
The ActivatedRoute is specific to each routed component that the Angular Router loads. It contains information about the route, its parameters, and additional data associated with the route. By injecting the ActivatedRoute, you are configuring the component to use a service.
实现ngOnInit:
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.product = products[+params.get('productId')];
});
}
The route parameters correspond to the path variables you define in the route. The URL that matches the route provides the productId. Angular uses the productId to display the details for each unique product.
在product detail Component显示product property的信息:
<h2>Product Details</h2>
<div *ngIf="product">
<h3>{{ product.name }}</h3>
<h4>{{ product.price | currency }}</h4>
<p>{{ product.description }}</p>
</div>
效果如下:
跳转时的调试:
跳转时选中的product的索引,通过参数productId传入到product detail Component里:
- 谁说 Java 要过时?2017年Java 大事件一览及未来前瞻
- mongodb的用法
- silverlight中如何将string(字符串)写入Resource(资源)?
- Python练习环境搭建-引入预定义数据
- 振幅和成交量的关系
- silverlight中的几个冷门标记 {x:Null},d:DesignWidth,d:DesignHeight
- 用scikit-learn和pandas学习线性回归
- 自动驾驶玩出新花招,以后老司机们就要失业了
- silverlight.net官方网站图片切换源码
- 制作iis自动安装包
- 安装程序无法复制一个或多个文件。特定错误码是0x4b8。
- silverlight中"制作逐帧动画"/"播放gif"收集
- Android新手之旅(1) 开发环境的安装
- Python安装模块
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 工具系列 | H5自定义视频播放器实现
- 前端系列 |原生JS和jQuery循环遍历函数
- 工具系列 | H5如何实现人脸识别
- 形式化分析工具(六):HLPSL Tutorial(Example3)
- CODING DevOps + Nginx-ingress 实现自动化灰度发布
- TF入门04-TF实现Word2Vec
- TF入门03-实现线性回归&逻辑回归
- TF入门02-TensorFlow Ops
- 前端|利用Verify插件实现前端图像验证码
- 3分钟短文 | PHP位运算和逻辑运算,一个符号写两遍这么简单?
- 打卡群刷题总结0721——搜索二维矩阵
- NumPy进阶80题完整版|附Notebook版本下载
- 【LeetCode每日一题】21. Merge Two Sorted Lists
- 计算广告笔记06-程序化交易广告
- TF入门05-实验过程管理