angular - Angular 5 将附加值作为查询参数传递
问题描述
在formNavigation.ts
(共享模块组件)中,我有:
@Input nextPath?:string
next() {
this.router.navigate([this.nextPath], {queryParamsHandling: "merge"})
}
在comp1.component.html
:
<form-navigation [nextPath]="'enroll/plans'"></form-navigation>
上面的代码工作正常,我正在通过注册/计划页面中的激活路由获取查询参数。
但我想传递一个附加值(索引 = 0)作为查询参数
<form-navigation [nextPath]="'enroll/plans'" {index:0}></form-navigation>
我尝试将上面的代码发送 index = 0 来注册/计划,但它显示错误。
解决方案
首先,如果你想传递查询参数,你必须这样做
this.router.navigate([this.nextPath], { queryParams: { x : val} } );
然后定义Input
参数,并将其绑定到您的html中。
所以你的最终代码看起来像这样
@Input() index: number;
this.router.navigate([this.nextPath], { queryParams: { index : this.index} } );
<form-navigation nextPath="enroll/plans" [index]="0"></form-navigation>
推荐阅读
- javascript - 如何在传单地图上添加叠加层?
- python - 在循环环境下将附加数据写入 xlsx 行而不覆盖的代码
- javascript - 如何停止在富文本编辑器中将“大于”和“小于”符号转换为实体?
- keycloak - 使用 kcadm cli 添加 LDAP 用户联合,但在进行任何领域设置更改之前无法在 UI 中显示
- python-3.x - GPhoto2 - 直接从相机获取焦距和传感器尺寸
- jenkins - 为什么 Jenkins 字符串参数为空?
- c# - 如何修复.Net核心中相同nuget包的多个版本的程序集绑定错误
- azure-functions - 在运行时 ~3 下无法在 Azure 函数上加载文件或程序集“Microsoft.Azure.WebJobs.EventHubs”
- java - Java:lambda 表达式连接多个字符串参数
- node.js - 当我控制台 req.body 它时,给我所有具有值的属性,但是当我获得单个属性值时,给我错误未定义