UI 路由器在使用数组操作时停止工作
UI Router stops working when operating with arrays
假设我有一组标签:
$scope.tagArray = ['monkey', 'giraffe'];
然后做一个:
$location.search('tags', $scope.tagArray);
然后第一次工作完美 - URL 更改为:
http://localhost:8000/#/?tags=monkey&tags=giraffe
但是...如果我将数组更改为:
$scope.tagArray = ['monkey'];
然后 运行 我再次搜索:
$location.search('tags', $scope.tagArray);
那么URL仍然是:
http://localhost:8000/#/?tags=monkey&tags=giraffe
我什至尝试将 undefined 解析为 $location.search 的参数,但一旦我搜索了一个数组 - 我就无法再次更改 'tags'。
有没有人有同样的经历?或者可能有线索?
因为它更新了第一个参数。
文档:
If search is a string or number, then paramValue will override only a
single search property.
我认为正确的方法是在这种情况下使用对象参数而不是字符串:
$location.search({ tags: 'monkey' });
我最后所做的实际上只是在每次有人点击搜索按钮时重置 $state.params。
$state.params = [];
重置后我制作了所有 $location.search。我认为这不是最好的方法,但效果很好。
假设我有一组标签:
$scope.tagArray = ['monkey', 'giraffe'];
然后做一个:
$location.search('tags', $scope.tagArray);
然后第一次工作完美 - URL 更改为:
http://localhost:8000/#/?tags=monkey&tags=giraffe
但是...如果我将数组更改为:
$scope.tagArray = ['monkey'];
然后 运行 我再次搜索:
$location.search('tags', $scope.tagArray);
那么URL仍然是:
http://localhost:8000/#/?tags=monkey&tags=giraffe
我什至尝试将 undefined 解析为 $location.search 的参数,但一旦我搜索了一个数组 - 我就无法再次更改 'tags'。
有没有人有同样的经历?或者可能有线索?
因为它更新了第一个参数。
文档:
If search is a string or number, then paramValue will override only a single search property.
我认为正确的方法是在这种情况下使用对象参数而不是字符串:
$location.search({ tags: 'monkey' });
我最后所做的实际上只是在每次有人点击搜索按钮时重置 $state.params。
$state.params = [];
重置后我制作了所有 $location.search。我认为这不是最好的方法,但效果很好。