通过Angular中的路由路径发送数据 [英] Send data through routing paths in Angular

查看:100
本文介绍了通过Angular中的路由路径发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,使用router.navigate将数据作为参数发送?
我的意思是,类似于



2)可选路线参数:





3)路由查询参数:





4)您可以使用服务将数据从一个组件传递到另一个组件,而无需使用任何路由参数。



有关示例,请参见: https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/



我在这里有个笨蛋: https://plnkr.co/edit/KT4JLmpcwGBM2xdZQeI9?p =预览


Is there anyway to send data as parameter with router.navigate? I mean, something like this example, as you can see the route has a data parameter, but doing this it's not working:

this.router.navigate(["heroes"], {some-data: "othrData"})

because some-data is not a valid parameter. How can I do that? I don't want to send the parameter with queryParams.

解决方案

There is a lot of confusion on this topic because there are so many different ways to do it.

Here are the appropriate types used in the following screen shots:

private route: ActivatedRoute
private router: Router

1) Required Routing Parameters:

2) Route Optional Parameters:

3) Route Query Parameters:

4) You can use a service to pass data from one component to another without using route parameters at all.

For an example see: https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/

I have a plunker of this here: https://plnkr.co/edit/KT4JLmpcwGBM2xdZQeI9?p=preview

这篇关于通过Angular中的路由路径发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆