yatg
yatg

Reputation: 1141

Append Param on locationChangeStart

When a user for example hits the back button of my application i do window.history.back() which triggers there locationChangeStart in here I want to append .search({param:'value'}) as per this topic here: Passing parameter inside $location.path in Angular

Is this possible to be done?

Edit:

This is what I tried:

            ]).config(appRoute).run(function ($rootScope, $route) {
                $rootScope.passArgs = {};
                ang.rootScope = $rootScope;
                ang.route = $route;

                $rootScope.$on('$locationChangeStart', function (a, b, c) {
                    for (var aArg in $rootScope.passArgs) {
                        $route.current.params[aArg] = $rootScope.passArgs[aArg];
                        delete $rootScope.passArgs[aArg];
                    }
                });

Upvotes: 0

Views: 146

Answers (1)

Chrillewoodz
Chrillewoodz

Reputation: 28338

You could do it like this instead which will simplify it by a mile.

<button class="back-button" ng-click="back()">Go back</button>

$scope.back = function() {
  $location.path('my-path').search({isBack: true});
}

Upvotes: 1

Related Questions