lundi 25 juillet 2016

AngularJS multiples http.get

Hi guys im a newbie in AngularJS I have a problem calling multiples http.get. $scope.countries is getting values from cities. What happend? How can calling multiple http.get?

$scope.getInfo = function(){
    $scope.refreshing=true;
    //cities
    $http.get(baseUrl+'cities/GET_INFO/ALL').success(function(data) {            
        $scope.cities = data[0];
        $scope.cities.signal = $scope.getSignal(data[0].status);        
        $scope.refreshing=false;    
        alert('city');
    });      


    //countries
    $http.get(baseUrl+'countries/GET_INFO/ALL').success(function(data) {
        $scope.countries = data[0];            
        $scope.countries.signal = $scope.getSignal(data[0].status);
        $scope.refreshing=false;
        // alert('countries');
    });
}

Also I tried with:

$scope.getInfo2 = function(){
    $scope.refreshing=true;
    alert ('start');

    $scope.urlcities = $http.get(baseUrl+'cities/GET_INFO/ALL');
    $scope.urlcountries = $http.get(baseUrl+'cities/GET_INFO/ALL');

    $q.all([$scope.urlcities, $scope.urlcountries]).then(function(values) {
        alert('finish');             
        $scope.refreshing=false;
    });
}

But this code get an error.. Thanks so much for your help !

Aucun commentaire:

Enregistrer un commentaire