question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$push({new:'record'}) to child of $firebase reference?

See original GitHub issue

I have a $firebase ref to ‘a/b’ and wish to push a new record to ‘a/b/c’ (i.e. have firebase create new key with value {new:‘record’}), such that it will result in: a/b/c/-Joi2392d09 with {new:‘record’} as its value.

How do I go about doing this?

// Setup
var db = new Firebase('https://example.firebaseio.com/');
$scope.remote = $firebase(db.child('a/b')).$asObject();

// How do we push to a/b/c?
$scope.remote.c.$push({new:'record'}); // error - $push is not a function.

I can try using $inst(), but i can only push to ‘a/b’; I do not know how to $push a record to a child of the reference. Any ideas?

Thank you! Love the changes to the API in the latest release.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
katowulfcommented, Aug 22, 2014

There’s really no need for $child. You can use any ref to create a $firebase object (which is probably not necessary, since you can just drop to the API level).

var data = {new: 'record'};
var db = new Firebase('https://example.firebaseio.com/a/b');

// probably simplest and what you want
db.child('c').push(data);

// also fine, if you think scope needs to be compiled 
// (but it won't since you are using AngularFire objects which take care of this)
$firebase(db.child('c')).$push(data);

// if you already have a $firebase object
$firebase(db).$ref().child('c').push(data);

// or like this
var parent = $firebase(db);
$firebase( parent.$getRef().child('c') ).$push(data);
0reactions
vineshhpatelcommented, Nov 3, 2014
Read more comments on GitHub >

github_iconTop Results From Across the Web

$push({new:'record'}) to child of $firebase reference? #402
I have a $firebase ref to 'a/b' and wish to push a new record to 'a/b/c' (i.e. have firebase create new key with...
Read more >
Saving Data | Firebase Realtime Database - Google
Every time you push a new node onto a list, your database generates a unique key, ... The data for your app is...
Read more >
Add an item to a list in Firebase Database - Stack Overflow
The basic flow for inserting new record is as follows: private DatabaseReference mDatabase; // get reference to your Firebase Database.
Read more >
Creating custom key for new record in Realtime Database ...
Creating custom key for new record in Realtime Database Firebase | Angular. · import { AngularFireDatabase } from '@angular/fire/database'; · this.dbRef.child(` ...
Read more >
AngularFire - A real-time backend for AngularJS from Firebase.
This is the equivalent of calling push(value) on a Firebase reference. ... If a key is provided, it sets the value of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found