0

Let's say my current location is /phones

I want to route to a different controller and generate a url like /phonedetails?brand=x&size=y&price=z

How can I set up the route and controller?

//partial phonelist.html

<form id="phones-form">
 <input id="brand" type="text" placeholder="brand" ng-model="phoneInfo.brand">
 <input id="size" type="text" placeholder="size" ng-model="phoneInfo.size">
 <input id="price" type="text" placeholder="price" ng-model="phoneInfo.price">
 <button type="submit" class="btn btn-primary btn-lg" ng-click="getPhones()">Search</button>
</form>

//controller
$scope.phoneInfo = {};
$scope.getPhones() { 
  $location.search($scope.phoneInfo);
}

$location.search() generates a url like /phones?brand=x&size=y&price=z and doesn't transfer control to the other controller.

Maybe I am completely wrong in my understanding of routes. What is the right way to achieve this?

1 Answer 1

2

$location.search() will only control the query string. To change the location, you need to use $location.path().

$scope.getPhones() { 
    $location.search($scope.phoneInfo);
    $location.path('/phonedetails');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.