Hey Derek,

Let me take this piece by piece:

*Is it possible to batch remove items from a firebase array using $remove?*

Not directly via $remove or any of the $firebaseArray methods, although you
could do batch removes via the regular Firebase SDK's update() method by
passing null as the value for several keys. For example:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.update({
   foo: null,
   bar: null
});

Will batch remove the foo and bar children from ref while keeping all other
children untouched.

*I'd like to automatically delete chat messages once the chat message list
becomes a certain length.*

Lucky for you, there is an even simpler way to make this happen! You should
check out Firebase queries
<https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries>,
specifically the limitToFirst()
<https://www.firebase.com/docs/web/api/query/limittofirst.html> and
limitToLast() <https://www.firebase.com/docs/web/api/query/limittolast.html>
methods. You can limit a $firebaseArray to the last five items and it will
automatically update when new items are added or removed. The code would
look something like this:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
var messagesRef = ref.child("messages").limitToLast(5);
var messages = $firebaseArray(messagesRef);

Give that a shot and let me know if you have further questions.

Cheers!
Jacob
On Tue, Sep 1, 2015 at 6:55 PM, Derek Sifford wrote:

Hello, I've looked all over and haven't found anything on this.

Is it possible to batch remove items from a firebase array using .$remove?

I'm currently working on an app with a chat function in which I'd like to
automatically delete chat messages once the chat message list becomes a
certain length.

Ideally, I'd do it like this (if, for example, I wanted the messages list
only 5 messages long):

if ($scope.messages.length > 5) {
$scope.messages.$remove($scope.messages.length - 5, $scope.messages.
length);
}


Please help! I've tried everything...

--
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/74c24173-ca53-4d65-a63c-c4ec80198606%40googlegroups.com
<https://groups.google.com/d/msgid/firebase-angular/74c24173-ca53-4d65-a63c-c4ec80198606%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CAGcMwsA_BESWo9PYtysTWB0tYifFU0WV-oawk5SCf3rKo0qwJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
groupfirebase-angular @
postedSep 2, '15 at 3:26a
activeSep 2, '15 at 5:31a
posts2
users2

2 users in discussion

Jacob Wenger: 1 post Derek Sifford: 1 post

People

Translate

site design / logo © 2021 Grokbase