2017-05-30 64 views
0

我使用Ionic v1并遇到问题。这个错误有很多标题。但我找不到解决方案。每次打开页面时都会运行离子Web服务

我这样做,

<ion-nav-view name="other" cache-view="false"></ion-nav-view> 

$stateProvider.state('app', { 
    url: '/app', 
    cache: false, 
    abstract: true, 
    templateUrl: 'templates/menu.html', 
    controller: 'AppCtrl' 
}) 

运行控制器每次页面被打开的时间。但我的web服务代码只能先开

当我的代码运行:

.controller('PlaylistsCtrl', function($scope, $rootScope, $http, $ionicPopup) { 

    $scope.loadingShow(); 

    console.log("Test"); //Run everytime but $http run only first opened 

    $http.get($scope.webServiceUrl + "json_getSharedPicture.php") 
     .then(function(response) { 
      $scope.loadingHide(); 
      $rootScope.playlists = response.data; 
     }); 

}) 

我离子信息:

global packages: 

    @ionic/cli-utils : 1.2.0 
    Cordova CLI  : 7.0.1 
    Ionic CLI  : 3.2.0 

local packages: 

    @ionic/cli-plugin-cordova : 1.2.1 
    @ionic/cli-plugin-ionic1 : 1.2.0 
    Cordova Platforms   : android 6.2.3 ios 4.4.0 
    Ionic Framework   : ionic1 1.3.3 

System: 

    Node  : v6.10.3 
    OS   : Windows 10 
    Xcode  : not installed 
    ios-deploy : not installed 
    ios-sim : not installed 

回答

1
If you want to hit your code every time you load that page. 

你需要初始化函数,调用它

function onLoad() { 
$http.get($scope.webServiceUrl + "json_getSharedPicture.php") 
    .then(function(response) { 
     $scope.loadingHide(); 
     $rootScope.playlists = response.data; 
    }); 
}onLoad(); 
相关问题