How can I change params in url with AngularJS?
angularjs, javascript
Solution
`$location.search` will create an url like:
http://localhost/test/year/2012?year=2013
which is not what you want. You need to use `$location.url()`:
function OverviewCtrl($scope,$routeParams, $location) {
$scope.yearIsChanged = function () {
$location.url('/test/year/' + $scope.year);
}
}
Problem
I want change the url in my angularjs app on the fly by tipping in a inputfield. e.g. - I stay on: `http://localhost/test/year/2012` - I will change on the side via a input field the year to 2013 that call my yearIsChanged function, than the url should changed to `http://localhost/test/year/2013` - But with my current configuration the url is changed to `http://localhost/test/year/2012/?year=2013` My modul configuration. ``` var module = angular.module('exampleApp'). config(['$routeProvider', function ($routeProvider) { $routeProvider. when('/test/year/:year', {templateUrl: 'partials/test.html', controller: OverviewCtrl, reloadOnSearch: false}). otherwise({redirectTo: '/'}); }]); ``` Controller action: ``` function OverviewCtrl($scope,$routeParams, $location) { $scope.yearIsChanged = function () { $location.search('year', $scope.year); } } ```