?
Solved

Retrieve data from firebase with promise in AngularJS/Ionic Application

Posted on 2016-08-23
1
Medium Priority
?
342 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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.
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…

752 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