我使用$state.go();来切换页面
其中有些页面的数据是动态的,我希望每次进来都重新加载数据。
请问如何每次当切换到这个页面时都重新加载页面(重新执行controller中的方法)?
PS:
$state.go('page',null,{
reload:true
});
这个也并没有效果
app.run(['$rootScope', '$location',
function($rootScope, $location) {
$rootScope.$on('$stateChangeStart', function(evt, next, current) {
alert('route begin change');
});
}
]);
我在这里获得了state变化的事件 然而并不知道如何刷新$scope...
PS2:
我是这样实现的
$scope.$on('$stateChangeSuccess', function(evt, next, current) {
// 数据reload
});
不知道算不算土办法...
但是这样也出现一个新的问题
$stateChangeSuccess中的方法会触发2遍,这是什么情况呢?
You can save data into sessionStorage. Then broadcast in the listening event of $on below. Then listen to this broadcast event in the sub-layer controller.
No special processing is required. The code you write in the controller will be automatically executed every time you switch to this page
The controller will generate a new instance every time. Every time the state changes, the controller and the view are new instances. This is also consistent with the injection idea of angularjs. You can log it yourself in the controller code.
"The method in $stateChangeSuccess will be triggered twice" This is because you have written Controller information in both view and Route