在 Angular 中的 $location.path 中传递参数 [英] Passing parameter inside $location.path in Angular
本文介绍了在 Angular 中的 $location.path 中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想在我的控制器中使用 $location.path()
并且还传递一个自定义变量作为参数.所以我猜它看起来像这样:
I'm just trying to use $location.path()
in my controller but also passing a custom variable as a parameter. So it would look something like this I guess:
$scope.parameter = 'Foo';
$location.path('/myURL/' + $scope.parameter);
但这行不通.有人知道这应该如何在 Angular 中完成吗?
But that doesn't work. Anyone know how this is supposed to be done in Angular?
推荐答案
要添加参数,您应该使用 $location.search()
方法:
to add Parameters you should use $location.search()
method so:
$location.path('/myURL/').search({param: 'value'});
$location
方法可链接.
这个产品:
/myURL/?param=value
这篇关于在 Angular 中的 $location.path 中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文