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

标签 javascript angularjs angularjs-routing

根据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}}打印出“项目 1”。但是上面没有属性title ?

到底是什么$route.current包含?

最佳答案

$route.current对象有几个记录在案的属性,controller 就是其中之一。 $route.current 中可用 when 方法在路由定义对象中定义的所有属性,因为后者 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 对象原型(prototype)中的属性不会被序列化。 Angular 插值不应用作获取有值(value)的跟踪输出的可靠方式,请始终使用 console

关于javascript - AngularJs - $route.current 到底包含什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37127254/

相关文章:

typescript - 在 Angular2 中实现动态路由(Typescript)

javascript - 如何在 Highcharts 中设置新数据然后反转为原始数据?

javascript - Angular JS 拼接不起作用

javascript - 在 uitableview 单元格中显示项目的评分

javascript - 将 Controller 与指令分开?

angularjs - 视频自动播放错误

javascript - 解决进入路线前不跑

angularjs - $routeProvider 中的多个 url

javascript - 测试 Date 对象的升序 Javascript 数组

javascript - 找出(视差?)滚动效果