绑定到$ state属性时,Scope属性未更新

时间:2014-12-10 07:38:30

标签: angularjs angular-ui-router

使用UI路由器0.2.12。为什么$rootScope.$state绑定到$state对象本身会更新HTML中的表达式(更改UI状态时):

// index.html:
<!-- the JSON output is updated when transitioning to a new state -->
<div>Current state data: {{ $state.current.data | json }}</div>

// app.js:
angular.module('myApp', ['ui.router'])
.controller('AppController',
  function($rootScope, $state) {
    $rootScope.$state = $state; // <-- works
  }
);

但是,绑定到$ state对象的一个​​属性并不是:

// index.html:
<!-- the JSON output stays the same when transitioning to a new state -->
<div>Current state data: {{ $state.data | json }}</div>

// app.js:
angular.module('myApp', ['ui.router'])
.controller('AppController',
  function($rootScope, $state) {
    $rootScope.$state = $state.current; // <-- doesn't work
  }
);

谢谢。

0 个答案:

没有答案
相关问题