AngularJS - $routeParams Empty on $locationChangeSuccess

Posted by Marc M. on Stack Overflow See other posts from Stack Overflow or by Marc M.
Published on 2014-06-10T03:07:50Z Indexed on 2014/06/10 3:25 UTC
Read the original article Hit count: 233

Filed under:
|

I configure my app in the following run block. Basically I want to preform an action that requires me to know the $routeParams every $locationChangeSuccess.

However $routeParams is empty at this point! Are there any work rounds? What's going on?

app.run(['$routeParams', function ($routeParams) {

    $rootScope.$on("$locationChangeSuccess", function () {
        console.log($routeParams);
    });

}]);

UPDATE

function configureApp(app, user) {

    app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider.
            when('/rentroll', {
                templateUrl: 'rent-roll/rent-roll.html',
                controller: 'pwRentRollCtrl'
            }).

            when('/bill', {
                templateUrl: 'bill/bill/bill.html',
                controller: 'pwBillCtrl'
            }).

            when('/fileroom', {
                templateUrl: 'file-room/file-room/file-room.html',
                controller: 'pwFileRoomCtrl'
            }).

            when('/estate-creator', {
                templateUrl: 'estate/creator.html'
            }).

            when('/estate-manager', {
                templateUrl: 'estate/manager.html',
                controller: 'pwEstateManagerCtrl'
            }).

            when('/welcomepage', {
                templateURL: 'welcome-page/welcome-page.html',
                controller: 'welcomePageCtrl'
            }).

            otherwise({
                redirectTo: '/welcomepage'
            });
    }]);

    app.run(['$rootScope', '$routeParams', 'pwCurrentEstate','pwToolbar', function ($rootScope, $routeParams, pwCurrentEstate, pwToolbar) {

        $rootScope.user = user;



        $rootScope.$on("$locationChangeSuccess", function () {
            pwToolbar.reset();
            console.log($routeParams);
        });

    }]);

}

Accessing URL:

http://localhost:8080/landlord/#/rentroll?landlord-account-id=ahlwcm9wZXJ0eS1tYW5hZ2VtZW50LXN1aXRlchwLEg9MYW5kbG9yZEFjY291bnQYgICAgICAgAoM&billing-month=2014-06

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about angularjs