【发布时间】:2020-04-11 01:14:58
【问题描述】:
我正在开发一个 Angular 应用程序,并意识到在最新版本的 Angular 中,数据可以通过路由将一个组件传输到另一个组件。我浏览了一些博客,但我不太清楚如何做到这一点。
我的代码
component1.ts
sendMessageto2() {
par = this.param
this.router.navigate(['/vav'],{state : {data : {par}}})
console.log(this.param)
}
我想将变量this.param 传递给component2
component1.html
<area shape="rect" coords="818,232,917,262" (click)="sendMessageto2()">
component2.ts
ngOnInit() {
this.state$ = this.activatedRoute.paramMap
.pipe(map(() => window.history.state))
}
我不确定如何在 component2 中获取此数据。我收到 map 的错误。找不到地图。有人可以帮我吗?
谢谢
【问题讨论】:
-
我试过了,但我有问题,编辑了问题
-
获取不在main.ts中的组件中的数据:stackoverflow.com/questions/58796745/passing-data-using-router/…,获取main.component中的数据stackoverflow.com/questions/58886303/…。
标签: angular routing angular7-router