angular.js - angular 如何刷新页面
淡淡烟草味
淡淡烟草味 2017-05-15 16:52:27
0
4
571

我使用$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遍,这是什么情况呢?

淡淡烟草味
淡淡烟草味

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