Solved

Retrieve data from firebase with promise in AngularJS/Ionic Application

Posted on 2016-08-23
1
265 Views
Last Modified: 2016-08-24
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
0
Comment
Question by:Oliver2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
Oliver2000 earned 0 total points
ID: 41769144
I figured it out myself

firebase.database().ref('news')
  .then ( function (ref) {
        $scope.newslist = $firebaseArray(ref);
        $ionicLoading.hide();
        $scope.$broadcast('scroll.refreshComplete')
  });

Open in new window

0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
Ransomware is a growing menace to anyone using a computer or mobile device. Here are answers to some common questions about this vicious new form of malware.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question