Oliver2000
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:
My current controller looks like this:
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
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
});
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();
})
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.