Search code examples
angularjsangular-routing

current route in Angular js


I trying to add routing to my angular1-page. I add next routes:

.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when('/mailbox/:id', {
            controller: 'BoxList'
        }).
        when('/mailbox/:id/folder/:folderId', {
            controller: 'BoxList'
        });
})

and after it, just after load page trying to get routes and current routes in console log (console.log($route)):

enter image description here

but if I try to get current route like that console.log($route.current) I've got undefined error, but if I try to get $route.routes it works well.

What's wrong?

Thanks!

UPD:

Controller look like this:

 MailboxUI.controller('BoxList', function ($scope, $http, $location, $route, $routeParams) {

    $scope.$route = $route;
    $scope.$location = $location;
    $scope.$routeParams = $routeParams;
    console.log($route);
    }

Solution

  • You need to change route after reload at least, thus $routeChangeStart to be triggered and current becomes available.

    But also $routeChangeSuccess

    Broadcasted after a route change has happened successfully. The resolve dependencies are now available in the current.locals property.