angular.js - angular how to refresh the page
淡淡烟草味
淡淡烟草味 2017-05-15 16:52:27
0
4
610

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?

淡淡烟草味
淡淡烟草味

reply all(4)
洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template