5

According to the docs, $route.current contains controller and locals.

For example, if this is one of my route:

    $routeProvider
    .when('/item1/:value', {
        templateUrl: 'item1.html',
        controller: 'Item1Controller',
        title: 'Item 1'
    });

{{$route.current}} prints out {"params":{"value":"value1"},"pathParams":{"value":"value1"},"loadedTemplateUrl":"item1.html","locals":{"$template":"<p>item 1:{{params}}</p>","$scope":"$SCOPE"},"scope":"$SCOPE"}

  1. Why isn't there controller?

  2. {{$route.current.title}} prints out "Item 1." But above there isn't property title?

What exactly does $route.current contain?

Shawn
  • 2,675
  • 3
  • 25
  • 48
  • How and where are you *"printing it out"*? FYI, `JSON.stringify()` does not print out function properties – Phil May 10 '16 at 00:06
  • Like the example in the docs, assign `$route` to the `$rootScope` and then in the html just use `{{$route.current}}`. – Shawn May 10 '16 at 00:10

1 Answers1

5

$route.current object has several documented properties, and controller is one of them. All properties that were defined in route definition object with when method are available in $route.current, because the latter prototypically inherits from a copy of the former:

$route.current.hasOwnProperty('controller') === false;

Object.getPrototypeOf($route.current).hasOwnProperty('controller') === true;

'controller' in $route.current === true;

The properties that are stored in $route.current object prototype aren't serialized when the object is converted to string. Angular interpolation shouldn't be used as a trusted way to get valuable tracing output, always use console instead.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • Got it. Thanks. The example in the docs also prints out `{{$route.current.params}}` and `{{$route.current.scope.name}}`. Well, why are these two properties `params` and `scope` not documented? I'm new to AngularJs, and I really hope the documentation is complete. – Shawn May 10 '16 at 00:47
  • @Shawn params isn't documented because the suggested way to retrieve it is `$routeParams`. And there's hardly a single good use for `$route.current.scope`. You are free to use whatever you will find there, e.g. `$route.current.originalPath` is undocumented but a useful one. – Estus Flask May 10 '16 at 01:06