I want change the url in my angularjs app on the fly by tipping in a inputfield.
e.g.
http://localhost/test/year/2012
http://localhost/test/year/2013 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);
    }   
}
                $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);
    }   
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With