Javascript 如何在Ionic framework中启动时加载$http服务应用程序?

Javascript 如何在Ionic framework中启动时加载$http服务应用程序?,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,如何在Ionic framework中启动时加载$http服务应用程序 //这是一项服务 //这是一个控制器 如果按下该按钮,则会加载数据。如何使数据在启动时加载?使用ionic.Platform.ready方法 您可以在应用程序中的任何位置运行此方法,可以是factory或controller 但是添加var请求={'searchString':'name_fr'}$http.get,{cache:true},request.successfunctionresponse{newGames=r

如何在Ionic framework中启动时加载$http服务应用程序

//这是一项服务

//这是一个控制器

如果按下该按钮,则会加载数据。如何使数据在启动时加载?

使用ionic.Platform.ready方法


您可以在应用程序中的任何位置运行此方法,可以是factory或controller

但是添加var请求={'searchString':'name_fr'}$http.get,{cache:true},request.successfunctionresponse{newGames=response;};在控制器中-应用程序加载启动。
appModule.factory('NewGames', function($http, $ionicLoading) {
  // JSON Array

  var newGames = [];

  var request = {'searchString' : 'name_fr'};
  $http.get('http://example.com/rest/data.php', { cache: true}, request).success(function(response) {
      newGames = response;

  });


  return {
    all: function() {
      //$ionicLoading.hide(); 
      return newGames;

    }

  }
});
myApp.controller('MainCtrl', function($scope, NewGames, $ionicSlideBoxDelegate, $stateParams, $ionicPlatform) {


  $scope.nextSlide = function() {
    $ionicSlideBoxDelegate.next();
  }

  $scope.newGames = NewGames.all();

});