That was the right answer, thank you very much ! 

I had to use 

$scope.$apply();

for the HTML to display it, apparently it doesn't updates right away. Do 
you have any idea why ? I understand Angular has to be notified of a change 
for it to display, as explained very nicely here : 
http://jimhoskins.com/2012/12/17/angularjs-and-apply.html

What I don't understand, is why it's the case here ? Why is Angular unaware 
of the change ?

Thanks again !


Le vendredi 14 novembre 2014 16:01:22 UTC+2, Joberto Diniz a écrit :
>
> Your *MyLoc* service returns a promise and *angular 1.2.x* doesn't handle 
> promises bindings.
> You have to unwrap the promise, something like:
>
> MyLoc.then(function(data){
>   $scope.data.myLoc = data;
> });
>
>
>
>
> On Thursday, November 13, 2014 7:52:04 AM UTC-2, Jeremy Belolo wrote:
>>
>> Hello all,
>>
>> I'm starting to learn a lot of things related to the hybrid apps coding. 
>> I decided to go on and use Ionic framework, based on AngularJS (this gives 
>> me the occasion to learn it), and use Firebase as my backend solution.
>>
>> I want to setup a map in my app, so I would locate the user and some 
>> points of interests around him. I found out GeoFire existed, so I started 
>> working with it.
>>
>> My problem : I fail in displaying a user's location saved into Firebase. 
>> I query it using GeoFire, and get the response (console.log it) but it 
>> won't update the scope variable. 
>>
>> Here is the JS code :
>>
>>
>> myApp.factory("MyLoc", function(){
>>     var firebaseRef = new 
>> Firebase("https://myfirebase.firebaseio.com/geofire/";);
>>     var geoFire = new GeoFire(firebaseRef);
>>
>>     /*    geoFire.set("user_loc", [37.785326, -122.405696]).then(function() {
>>      console.log("Provided key has been added to GeoFire");
>>      }, function(error) {
>>      console.log("Error: " + error);
>>      });*/
>>
>>      return geoFire.get("user_loc").then(function(location) {
>>         if (location === null) {
>>             console.log("Provided key is not in GeoFire");
>>             return 0;
>>         }
>>         else {
>>             console.log("Provided key has a location of " + location);
>>             return location;
>>         }
>>     }, function(error) {
>>         console.log("Error: " + error);
>>         return 0;
>>     });
>> })
>>
>> myApp.controller("firstCtrl", function($scope, MyLoc) {
>>     $scope.data = {};
>>
>>     $scope.data.myLoc = MyLoc;
>> });
>>
>> The HTML just displays it :
>>
>>
>> {{data.myLoc}}
>>
>> Since I'm an Angular N00b, I guess I'm missing something obvious. I guess 
>> I should use a promise or something similar, just can't figure out how ! 
>> Can someone help me, please ? :)
>>
>> Thank you very much bros !
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to