Avatar of Oliver2000
Oliver2000
Flag for Brazil asked on

Retrieve data from firebase with promise in AngularJS/Ionic Application

Hi experts,

I have a Ionic Application where I try to include Firebase. I got it work so far but the way I included the get request in my controller my script just continue without waiting for the data. I would like to convert my request into a request with a promise.

something similar as I used before with normal $http requests:

 
$http(http_req).then(function mySucces(data) {
// Success
}, function myError(data) {
//something was wrong
});

Open in new window


My current controller looks like this:

.controller('NoticiasCtrl', function(FURL, $scope, $state, $http, $ionicLoading, $rootScope, $firebaseObject, $firebaseArray) {
	
    $scope.newslist = [];

    $scope.doRefresh = function() {
  
        //Show loading comment
    	$ionicLoading.show({
        template: '<p>Carregando notícias...</p><ion-spinner></ion-spinner>'
    	});

        var ref = firebase.database().ref('news');
        $scope.newslist = $firebaseArray(ref);

        $ionicLoading.hide();
        $scope.$broadcast('scroll.refreshComplete');

    	};

	$scope.doRefresh();

})

Open in new window


Basically I want to have the line "var ref = firebase...." with a promise. And if the data is received continue with $scope....

Thank you in advance
AngularJavaScriptMobile

Avatar of undefined
Last Comment
Oliver2000

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Oliver2000

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23