1

For example, i have this url: http://local.com/. When i called function in my SearchController i want set text=searchtext and get url like this: http://local.com/?text=searchtext.

How i can do it? I tried $location.search('text', 'value'); but got this url:

http://local.com/#?text=searchtext

$scope.searchTracks = function() {

        Search.search.get($scope.params, function(data) {
            /** Set params in query string */
            $location.search('text', $scope.text);
            $location.search('sorted', $scope.sorted);

        });

    }
1

1 Answer 1

1

You also need to specify the path :

$location
  .path('/path/to/new/url')
  .search({
    'text': $scope.text,
    'sorted': $scope.sorted
  });

And the final url will be something like:

http://localhost/path/to/new/url?text={{$scope.text}}&sorted={{$scope.sorted}}

Another way is to set them manually:

$location.url('/path/to/new/url?text' + $scope.text + '&sorted=' + $scope.sorted);
Sign up to request clarification or add additional context in comments.

3 Comments

hmm. first variant not work, i get like this: http://site.local/#/new/path?sorted=Relevance . it's strange
@illexial please update your question with the current code you are using, the url you pasted here seems correct
i tried this and it works, but once you refresh the page it stops working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.