Ionic tabs with synchronous http request


#1

I create an ionic project with tabs that displays dynamic list using this code in services.js:

.factory('Interventions', function($http,$q) {
var interventions = {};
   $http({
  url: 'http://172.20.1.1/list.php'
   }).success(function(data, status, headers, config) {
    interventions = data; });
 return {
        all: function() {
            var deferred = $q.defer();
            deferred.resolve(interventions);
            return deferred.promise;  },
        findById: function(interId) {
            var deferred = $q.defer();
           var intervention = interventions[interId - 1];
           deferred.resolve(intervention);
            return deferred.promise; },
        findByName: function(searchKey) {
            var deferred = $q.defer();
            var results = interventions.filter(function(element) {
                return element.Nom.toLowerCase().indexOf(searchKey.toLowerCase()) > -1;
            });
            deferred.resolve(results);
            return deferred.promise;
        } } })

and in controllers.js

.controller('InterventionCtrl', function($scope, $http, $timeout, Interventions) {
$scope.searchKey3 = "";
$scope.clearSearch = function () {
            $scope.searchKey3 = "";
            findAllInter();  }
$scope.search = function () {
            Interventions.findByName($scope.searchKey3).then(function (interventions) {
                $scope.interventions = interventions;  });  }
        var findAllInter = function() {
            Interventions.all().then(function (interventions) {
                $scope.interventions = interventions;
            });  }
        findAllInter();
})

Is there a solution to use synchronous method that calls the method all() only when data ara available (like callback)

Thank you in advance