I use $state.go(); to switch pages
The data on some of these pages is dynamic and I want the data to be reloaded every time I come in.
How can I reload the page (re-execute the method in the controller) every time I switch to this page?
PS:
$state.go('page',null,{
reload:true
});
This has no effect either
app.run(['$rootScope', '$location',
function($rootScope, $location) {
$rootScope.$on('$stateChangeStart', function(evt, next, current) {
alert('route begin change');
});
}
]);
I got the state change event here, but I don’t know how to refresh $scope...
PS2:
This is how I achieved it
$scope.$on('$stateChangeSuccess', function(evt, next, current) {
// 数据reload
});
I don’t know if this is a crude method...
But this also presents a new problem
The method in $stateChangeSuccess will be triggered twice. What is the situation?
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