Shawn Shawn - 1 year ago 70
Javascript Question

AngularJs - What exactly does $route.current contain?

According to the docs,


For example, if this is one of my route:

.when('/item1/:value', {
templateUrl: 'item1.html',
controller: 'Item1Controller',
title: 'Item 1'

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

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

What exactly does

Answer Source

$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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download