Javascript angularjs在每次显示页面时运行函数

Javascript angularjs在每次显示页面时运行函数,javascript,angularjs,ionic,Javascript,Angularjs,Ionic,我有以下代码: .controller('HomeCtrl', function( $scope, $http ) { $http.get( onlinePath + "/status" ).then(function(result) { if( result.data.status == true ) { $scope.currentStatus = result.data.userStatus; }

我有以下代码:

.controller('HomeCtrl', function( $scope, $http )
{
    $http.get( onlinePath + "/status" ).then(function(result)
    {
        if( result.data.status == true )
        {
            $scope.currentStatus = result.data.userStatus;
        }
    });
});
当此页面加载时(第一次打开时),它将获得联机状态并在该页面中显示

问题是,我导航应用程序,当我来到这个页面(我想它已经加载)时,它没有再次运行$http.get

如何知道页面何时再次打开(未加载)?

请查看:

特别是在“查看生命周期和事件”部分,它说视图是缓存的(一个可以配置的缓存),您可以监听一些特定的事件。。舞台

所以你可以做:

  $scope.$on("$ionicView.beforeEnter", function() {
    console.log("http call here");        
  });
看看:

特别是在“查看生命周期和事件”部分,它说视图是缓存的(一个可以配置的缓存),您可以监听一些特定的事件。。舞台

所以你可以做:

  $scope.$on("$ionicView.beforeEnter", function() {
    console.log("http call here");        
  });

在路由配置中,您可以添加缓存:false参数,例如

.state('app.home', {
    cache: false,
    url: '/home',
    views: {
        'menuContent': {
            templateUrl: 'templates/home.html',
            controller: 'HomeCtrl'
        }
    }
})

在路由配置中,您可以添加缓存:false参数,例如

.state('app.home', {
    cache: false,
    url: '/home',
    views: {
        'menuContent': {
            templateUrl: 'templates/home.html',
            controller: 'HomeCtrl'
        }
    }
})