AngularJs - $route.current 到底包含什么?

AngularJs - What exactly does $route.current contain?

根据 docs$route.current 包含 controllerlocals

例如,如果这是我的路线之一:

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

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

  1. 为什么没有controller

  2. {{$route.current.title}} 打印出来 "Item 1." 但是上面没有 属性 title?

$route.current具体包含什么?

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

当对象转换为字符串时,存储在 $route.current 对象原型中的属性不会被序列化。 Angular 不应将插值用作获取有价值的跟踪输出的可靠方式,请始终使用 console