首页 > angular 如何刷新页面

angular 如何刷新页面

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


controller每次都会生成一个新的实例的,每次state的改变,controller连带view都是新实例。这个跟angularjs的注入思想也比较一致。你可以自己在controller的代码里log一下。


"$stateChangeSuccess中的方法会触发2遍" 这个是因为你在view 和Route里面都写了Controller信息


不需要特别处理啊, 你写在controller中的代码, 每次切换到这个页面中时, 这里面的代码都会自动执行一次的


你可以把数据存进sessionStorage。接着在下边那个$on的监听事件中进行广播。然后在子层的controller中监听这个广播事件。

【热门文章】
【热门文章】