Search code examples
javascriptangularjsangularjs-scopeangularjs-routingangularjs-controller

$location.search() used with external function reset whole $scope. How to avoid it?


Example of problem: Plunker

Its about controller.js file. I am trying to pass cleanSearchParameters output into $location.search function and it does work, but after whole $scope gets reset.

Check console on example for more details. Try to check some checkboxes.


Solution

  • Set the reloadOnSearch parameter to false when you define the route:

    app.config(['$routeProvider',
        function($routeProvider) {
            $routeProvider.
            when('/', {
                templateUrl: 'bug.html',
                controller: 'appController',
                reloadOnSearch: false
            });
        }]);
    

    This will allow you to update the search parameters without reloading the controller.