我在将数据传递给其他组件时遇到问题。这是一个例子。
onEdit(data) {
this.router.navigate(["/edit", { state: data }], {
relativeTo: this.activatedRoute
});
}
还有我的路由器ts
file:
{
path: "edit",
component: ServiceTimeGoalUpdateComponent,
resolve: {
serviceTimeGoal: ServiceTimeGoalResolve
},
data: {
pageTitle: "ServiceTimeGoals",
data: "data"
}
},
And above snippets gives me:
我真正想要的是当我单击列表中的编辑按钮时,它应该导航到edit
以及一些数据。我究竟做错了什么 ?
@batgerel,您的代码中有错误。必须是
this.router.navigate(['./edit'],
{ relativeTo: this.activatedRoute, state: { data } })
而且,如果您的组件不是主应用程序,则在 ngOnInit 中
this.activatedRoute.paramMap.pipe(
take(1), //take(1) is for unsubscribe
map(() => window.history.state)
).subscribe(res => {
console.log(res.data)
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)