使用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
}
);
谢谢。