gpt4 book ai didi

location - AngularJS - 更新 $route 参数的最佳方式

转载 作者:行者123 更新时间:2023-12-03 21:19:12 24 4
gpt4 key购买 nike

我有几条不同的路线,但包含相似的参数。
示例:

when '/user/:accountId/charts/:chartType', controller:ChartsController
when '/manager/:accountId/charts/:chartType', controller:ChartsController
when '/whatever/pathy/paththingy/charts/:chartType', controller:ChartsController

请注意,所有三个 View 都使用相同的图表 Controller 来控制 View 。它是一个相当通用的 Controller ,但它需要在可用的图表类型之间切换……同时保留路线的其余部分。
示例:(这不起作用)
if my currrent url is '/user/001/charts/comparison'
Then I call something like:
$route.current.params.chartType = 'newChart';
$route.reload(); // or soemthing similar?
I want the url to become '/user/001/charts/newChart'

有没有人知道如何在不完全重新输入或重建路线路径的情况下轻松更新路线的参数?

最佳答案

从 angular 1.3 开始,您可以使用 $route.updateParams(newParams)更改路由参数。

Here is a quote from the angular docs...

$route.updateParams(newParams);

Causes $route service to update the current URL, replacing current route parameters with those specified in newParams. Provided property names that match the route's path segment definitions will be interpolated into the location's path, while remaining properties will be treated as query params.

关于location - AngularJS - 更新 $route 参数的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13636476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com