gpt4 book ai didi

angularjs - 更改 View 时在 AngularJS 中保留查询参数的最简单方法是什么?

转载 作者:行者123 更新时间:2023-12-05 01:07:28 25 4
gpt4 key购买 nike

在 Angular View 之间链接时,是否有一种简单的方法可以保留查询参数?

当我使用 ngHref 时,查询参数丢失:

<a ng-href='OtherPage'>Other page</a>

我从这个网址导航 http://localhost/Page.html#/?stat=77698382 ,至此: http://localhost/Page.html#/OtherPage .

此解决方案有效,但它需要一个具有显式重定向的函数:
<a ng-click='redirectToOtherPage()'>Other page</a> 

$scope.redirectToOrderListPage = function() {
$location.path('OtherPage');
};

有没有更声明性的方法来做到这一点?

最佳答案

这两者略有不同。我认为您正在寻找的代码是:

<a ng-href='#/OtherPage'>Other page</a>
http://localhost/Page.html#/?stat=77698382似乎关闭。

您需要将查询字符串放在哈希标记之前,如下所示:
http://localhost/Page.html?stat=77698382#/

然后当你浏览你的应用程序时,queryString 不会被替换。

关于angularjs - 更改 View 时在 AngularJS 中保留查询参数的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18657705/

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