Seglespaan Seglespaan - 10 months ago 75
AngularJS Question

Angular, using select input filter to update route?

I have my app set up where a list of products can be filtered by colour using a select input, I also have the

passing this colour param to the page if it is present in the url.

What I want to do now is update the url / route when the select box is changed. How do I bind the change of the select to the route?


select has an undocumented ng-change parameter that you can use to call a function to set $location.path:

<select ... ng-model="color" ng-change="updatePath()">


function MyCtrl($scope, $location) {
    $scope.updatePath = function() {
       $location.path(... use $scope.color here ...);