简体   繁体   English

角度位置搜索不适用于&

[英]Angular location search does not work with &

/course-home#/search?q=my%20lab%20%26%20mastering&%20kamal&ref=%2Ftab%2Factive / course-home#/ search?q = my%20lab%20%26%20mastering&%20kamal&ref =%2Ftab%2Factive

$scope.keyword = $location.search().q;

In my angular app when I search for "my lab & mastering" $location.search().q returns only "my lab" and does not return full string. 在我的角度应用程序中,当我搜索“我的实验室和母版”时,$ location.search()。q仅返回“我的实验室”,而不返回完整的字符串。 after the "&" it does not work properly. “&”之后,它将无法正常工作。 What is the best way to get query string from above URL ? 从上述URL获取查询字符串的最佳方法是什么?

create a $scope which is set to an array of symbols. 创建一个设置为符号数组的$scope Include in this array the & symbol and add it to your data. 在此数组中包含符号,并将其添加到您的数据中。

I think that is because it has the url encoding of %26 . 我认为这是因为它的URL编码为%26 Check out the W3C cheat sheet about URL encoding to see how exactly to reference them: 查看有关URL编码的W3C备忘单,以了解如何准确地引用它们:

URL encoding cheat sheet URL编码备忘单

Found the issue, and the issue was URL encoding not done properly. 发现了问题,问题是URL编码未正确完成。

$location.url('/search?q=' + searchText + '&ref=' + $location.$$path);

To fix the issue need to encode the searchText variable 要解决此问题,需要对searchText变量进行编码

$location.url('/search?q=' + encodeURIComponent(searchText) + '&ref=' + $location.$$path);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM