Hey,

I'm building an app and in one use case I want to write data into several
different locations.
(/messages/userID/, /pending/userID/, /user/userID/messages)

I'm connecting with a token created on my Django server.
I've tried creating a service\factory\simple function that returns a
$firebase object after connecting to a specific path with the token
but if I run 3 commands in the same scope function it only write to
firebase the last command, like for some reason each controller can hold
only one connection
and even though each time the connection is created with
new Firebase(url)

it still doesn't work.

this is what I have:

Token connect function:
$scope.token_auth = function(token,path, callback) {


         var url = 'https://#######.firebaseio.com' + path;
         var dataRef = new Firebase(url);
         dataRef.auth(token, function (error, result) {
             if (error)
             {
                 console.log('Login Failed!', error);


             }
             else
             {
                 var temp = $firebase(dataRef);
                 callback(temp);
             }
         });
     }


And in the function called from the view that need to write the data:
$scope.send_actual_message = function () {
         var token;


         $http({url: "../fire_token/",
             method: "GET",
             params: {'type': 'b'}}).then(function (response) {
             console.log(response);
             token = response.data.result;


             var author = 'b_' + $scope.bid;
             var receiver = 'i_' + $scope.in.id;


             $scope.token_auth(token,'/messages/' + author + '-' + receiver +
'/',function(data){
                 console.log(data);
                 var obj = data;
                 obj.$set({"brand":author, "influencer" : receiver});
             });

             $scope.token_auth(token,'/messages/' + author + '-' + receiver +
'/messages',function(data){
                  var obj = data.$asArray();
                 obj.$add({'author' : author, 'text' : $scope.text, 'time' :
Firebase.ServerValue.TIMESTAMP});
             });


             $scope.token_auth(token,'/users/' + receiver + '/messages/',
function(data){
                  var obj = data;
                 obj.$set(author, {"author" : author , "text" : $scope.text,
"date" : Firebase.ServerValue.TIMESTAMP}).then(function(ref){
                     // Setting priority as the latest message received\sent
                     ref.$priority = Firebase.ServerValue.TIMESTAMP;
                 });
             });


}, function (err) {
             console.log('error');
         });
     }



And as I said earlier, only the third call is written to firebase

Suggestions regarding a better service\provider\factory option and more
importantly one that allows me multiple connection are needed...

Thanks

--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/722336e1-3ae8-4168-8ca4-b69ec2b91823%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupfirebase-angular @
postedOct 7, '14 at 1:59p
activeOct 8, '14 at 8:21a
posts3
users2

2 users in discussion

Guy Tamir: 2 posts Michael Wulf: 1 post

People

Translate

site design / logo © 2021 Grokbase