FAQ
I am trying to filter a $firebaseArray to only load matching "hashtag"
values. I need to do this from the controller rather than the view because
I am using a 'ui-sortable' module which is dependent on a correct $index.

I cannot use something like:
$scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
because it returns a new array that is not a $firebaseArray.

Kato posted a possible solution
here: https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
quite get how this works. Here's my
attempt: http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

Can anyone please explain how to $filter a firebaseArray?

--
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/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Kato Richardson at Jun 1, 2015 at 2:34 pm
    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add doesn't
    work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato

    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk wrote:

    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not quite
    get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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/CADypTEaBxDCTsJYg1jzV7EtPjfN7WXZcY%3D08YpB3iG3f32V3QQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrey Kondratyuk at Jun 1, 2015 at 6:50 pm
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to filter
    server-side.
    Right, that's the goal. I need to reduce the data set so that it returns
    only the filtered items. I need an accurate $index in ng-repeat because I'm
    using a module called 'ui-sortable' to drag and drop sort the tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue and had
    to sort via the controller instead. Using the regular $filter service
    didn't quite work because it returns an array that is not a $firebaseArray
    which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add doesn't
    work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and updating
    the plunker sorry. The main issue I am having now is that I cannot get the
    filter to re-run when I make changes to $scope.hashtag. I made a new
    plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out another
    solution that added a new method to $extend $firebaseArray runs every time
    the model is changed at all like this: ng-repeat="thing in things.filter()"
    but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey

    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv
    <javascript:>> wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not quite
    get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.

    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv
    <javascript:>> wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not quite
    get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.

    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv
    <javascript:>> wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not quite
    get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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/194875b9-d72b-4306-95bd-bdc9955694f0%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrey Kondratyuk at Jun 1, 2015 at 6:51 pm
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to filter
    server-side.
    Right, that's the goal. I need to reduce the data set so that it returns
    only the filtered items. I need an accurate $index in ng-repeat because I'm
    using a module called 'ui-sortable' to drag and drop sort the tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue and had
    to sort via the controller instead. Using the regular $filter service
    didn't quite work because it returns an array that is not a $firebaseArray
    which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add doesn't
    work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and updating
    the plunker sorry. The main issue I am having now is that I cannot get the
    filter to re-run when I make changes to $scope.hashtag. I made a new
    plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out another
    solution that added a new method to $extend $firebaseArray runs every time
    the model is changed at all like this: ng-repeat="thing in things.filter()"
    but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv
    <javascript:>> wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not quite
    get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kato Richardson at Jun 1, 2015 at 7:03 pm
    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato

    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk wrote:

    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to filter
    server-side.
    Right, that's the goal. I need to reduce the data set so that it returns
    only the filtered items. I need an accurate $index in ng-repeat because I'm
    using a module called 'ui-sortable' to drag and drop sort the tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue and
    had to sort via the controller instead. Using the regular $filter service
    didn't quite work because it returns an array that is not a $firebaseArray
    which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out another
    solution that added a new method to $extend $firebaseArray runs every time
    the model is changed at all like this: ng-repeat="thing in things.filter()"
    but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
    quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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/CADypTEa-rbx%3Df0cognaiRm2kAtDNx4HGNoj%3D5PaDuDWoF5toZg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrey Kondratyuk at Jun 1, 2015 at 7:27 pm
    Would this work to only return a subset of items based on hashtags? The
    object looks like this:

    things: {
         thingID1: {
           something: 'value';
         },
         thingID2: {
          something: 'value'
         },
        ...}

    I need to load only a subset of things that match the value of 'something'.


    On Monday, June 1, 2015 at 3:03:13 PM UTC-4, Michael Kato Wulf wrote:

    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk <and...@dsrp.tv
    <javascript:>> wrote:
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to filter
    server-side.
    Right, that's the goal. I need to reduce the data set so that it returns
    only the filtered items. I need an accurate $index in ng-repeat because I'm
    using a module called 'ui-sortable' to drag and drop sort the tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue and
    had to sort via the controller instead. Using the regular $filter service
    didn't quite work because it returns an array that is not a $firebaseArray
    which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out another
    solution that added a new method to $extend $firebaseArray runs every time
    the model is changed at all like this: ng-repeat="thing in things.filter()"
    but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
    quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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/cb202b6c-0292-4089-885e-e897df7bf647%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kato Richardson at Jun 1, 2015 at 9:34 pm
    Please read the query docs
    <https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries>.
    It's only a couple pages of text and examples, and very enlightening.

    Cheers,
    Kato

    On Mon, Jun 1, 2015 at 12:27 PM, Andrey Kondratyuk wrote:

    Would this work to only return a subset of items based on hashtags? The
    object looks like this:

    things: {
    thingID1: {
    something: 'value';
    },
    thingID2: {
    something: 'value'
    },
    ...}

    I need to load only a subset of things that match the value of
    'something'.


    On Monday, June 1, 2015 at 3:03:13 PM UTC-4, Michael Kato Wulf wrote:

    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to filter
    server-side.
    Right, that's the goal. I need to reduce the data set so that it returns
    only the filtered items. I need an accurate $index in ng-repeat because I'm
    using a module called 'ui-sortable' to drag and drop sort the tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue and
    had to sort via the controller instead. Using the regular $filter service
    didn't quite work because it returns an array that is not a $firebaseArray
    which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out another
    solution that added a new method to $extend $firebaseArray runs every time
    the model is changed at all like this: ng-repeat="thing in things.filter()"
    but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to filter
    server-side. If the goal is to filter the content in the view, filtering in
    the ng-repeat, as intended by the Angular code, seems more ideal. Any
    reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    I am trying to filter a $firebaseArray to only load matching "hashtag"
    values. I need to do this from the controller rather than the view because
    I am using a 'ui-sortable' module which is dependent on a correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray, 'hashtag');
    because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
    quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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/cb202b6c-0292-4089-885e-e897df7bf647%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%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/CADypTEYikG51Q6pT735VWFhcFqzscq4uudN_vFbO4sY1V5TJJg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrey Kondratyuk at Jun 2, 2015 at 3:41 am
    Thanks. That was very enlightening but I've unfortunately run into a
    problem.

    The value of hashtag is an array. When I do orderByChild('hashtag') that is
    ordering by array values and when I add .equalTo(hashtag) that is trying to
    compare to a string value. Is there a step in-between here or something
    else I need to do first?

    Thanks,
    Andrey



    On Monday, June 1, 2015 at 5:34:57 PM UTC-4, Michael Kato Wulf wrote:

    Please read the query docs
    <https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries>.
    It's only a couple pages of text and examples, and very enlightening.

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 12:27 PM, Andrey Kondratyuk <and...@dsrp.tv
    <javascript:>> wrote:
    Would this work to only return a subset of items based on hashtags? The
    object looks like this:

    things: {
    thingID1: {
    something: 'value';
    },
    thingID2: {
    something: 'value'
    },
    ...}

    I need to load only a subset of things that match the value of
    'something'.


    On Monday, June 1, 2015 at 3:03:13 PM UTC-4, Michael Kato Wulf wrote:

    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to filter
    server-side.
    Right, that's the goal. I need to reduce the data set so that it
    returns only the filtered items. I need an accurate $index in ng-repeat
    because I'm using a module called 'ui-sortable' to drag and drop sort the
    tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue and
    had to sort via the controller instead. Using the regular $filter service
    didn't quite work because it returns an array that is not a $firebaseArray
    which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out another
    solution that added a new method to $extend $firebaseArray runs every time
    the model is changed at all like this: ng-repeat="thing in things.filter()"
    but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to
    filter server-side. If the goal is to filter the content in the view,
    filtering in the ng-repeat, as intended by the Angular code, seems more
    ideal. Any reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    I am trying to filter a $firebaseArray to only load matching
    "hashtag" values. I need to do this from the controller rather than the
    view because I am using a 'ui-sortable' module which is dependent on a
    correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray,
    'hashtag'); because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
    quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%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/7e56cc9d-ae9f-4402-b981-bdd5a96dc4ab%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Frank van Puffelen at Jun 2, 2015 at 4:12 am
    Firebase queries compare single values, not arrays. There are currently no
    "contains" or "oneOf" operators.

    If you want to query on something that isn't supported by Firebase's
    built-in query mechanism, you can often get the same result by building
    your own so-called index. The goal of such an index is purely to serve
    whatever need you have.

    I'll provide an example below. Note that I picked just one possible
    use-case, just so we have something concrete. The solution applies equally
    to other Things, Somethings and Values, but I find it easier to explain
    this using less generic terms.

    Say that you have a collection of users and each user can have multiple
    phone numbers.

         users
             twitter:346724367
                 name: "Frank van Puffelen"
                 phonenumbers
                     408123456: true
                     622996143: true
             password:63474326
                 name: "Andrey Kondratyuk "
                 phonenumbers
                     213018265: true
                     703509211: true

    Now say you want to look up a user by their phone number. You would create
    an index that maps phone numbers to users:

         uid_by_phonenumber
             408123456: twitter:346724367
             622996143: twitter:346724367
             213018265: password:63474326
             703509211: password:63474326

    On this you can do a query with:


    ref.child('uid_by_phonenumber').orderByKey().equalTo(408123456).once('child_added',
    function(snapshot) {
             var uid = snapshot.val();
             ref.child('users').child(uid).once('value', function(userSnapshot) {
                 var user = userSnapshot.val();
             });
         });

    You could use the same index to check if a phone number has already been
    registered, for example when a new user registers.

            Frank

    On Monday, June 1, 2015 at 8:41:19 PM UTC-7, Andrey Kondratyuk wrote:

    Thanks. That was very enlightening but I've unfortunately run into a
    problem.

    The value of hashtag is an array. When I do orderByChild('hashtag') that
    is ordering by array values and when I add .equalTo(hashtag) that is trying
    to compare to a string value. Is there a step in-between here or something
    else I need to do first?

    Thanks,
    Andrey



    On Monday, June 1, 2015 at 5:34:57 PM UTC-4, Michael Kato Wulf wrote:

    Please read the query docs
    <https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries>.
    It's only a couple pages of text and examples, and very enlightening.

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 12:27 PM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Would this work to only return a subset of items based on hashtags? The
    object looks like this:

    things: {
    thingID1: {
    something: 'value';
    },
    thingID2: {
    something: 'value'
    },
    ...}

    I need to load only a subset of things that match the value of
    'something'.


    On Monday, June 1, 2015 at 3:03:13 PM UTC-4, Michael Kato Wulf wrote:

    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to
    filter server-side.
    Right, that's the goal. I need to reduce the data set so that it
    returns only the filtered items. I need an accurate $index in ng-repeat
    because I'm using a module called 'ui-sortable' to drag and drop sort the
    tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue
    and had to sort via the controller instead. Using the regular $filter
    service didn't quite work because it returns an array that is not a
    $firebaseArray which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out
    another solution that added a new method to $extend $firebaseArray runs
    every time the model is changed at all like this: ng-repeat="thing in
    things.filter()" but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to
    filter server-side. If the goal is to filter the content in the view,
    filtering in the ng-repeat, as intended by the Angular code, seems more
    ideal. Any reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    I am trying to filter a $firebaseArray to only load matching
    "hashtag" values. I need to do this from the controller rather than the
    view because I am using a 'ui-sortable' module which is dependent on a
    correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray,
    'hashtag'); because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
    quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%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/e04376cf-4e2e-4fcf-bb57-3274f623d570%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrey Kondratyuk at Jun 2, 2015 at 3:42 pm
    Thanks. To create an "index that maps" would I need to separately run an
    angular.forEach on the main data and then re-save part of it (and keep it
    in sync manually)?

    It seems like I was so closed with the $extend firebaseArray method. It's a
    shame that won't work.
    On Tuesday, June 2, 2015 at 12:12:56 AM UTC-4, Frank van Puffelen wrote:

    Firebase queries compare single values, not arrays. There are currently no
    "contains" or "oneOf" operators.

    If you want to query on something that isn't supported by Firebase's
    built-in query mechanism, you can often get the same result by building
    your own so-called index. The goal of such an index is purely to serve
    whatever need you have.

    I'll provide an example below. Note that I picked just one possible
    use-case, just so we have something concrete. The solution applies equally
    to other Things, Somethings and Values, but I find it easier to explain
    this using less generic terms.

    Say that you have a collection of users and each user can have multiple
    phone numbers.

    users
    twitter:346724367
    name: "Frank van Puffelen"
    phonenumbers
    408123456: true
    622996143: true
    password:63474326
    name: "Andrey Kondratyuk "
    phonenumbers
    213018265: true
    703509211: true

    Now say you want to look up a user by their phone number. You would create
    an index that maps phone numbers to users:

    uid_by_phonenumber
    408123456: twitter:346724367
    622996143: twitter:346724367
    213018265: password:63474326
    703509211: password:63474326

    On this you can do a query with:


    ref.child('uid_by_phonenumber').orderByKey().equalTo(408123456).once('child_added',
    function(snapshot) {
    var uid = snapshot.val();
    ref.child('users').child(uid).once('value', function(userSnapshot)
    {
    var user = userSnapshot.val();
    });
    });

    You could use the same index to check if a phone number has already been
    registered, for example when a new user registers.

    Frank

    On Monday, June 1, 2015 at 8:41:19 PM UTC-7, Andrey Kondratyuk wrote:

    Thanks. That was very enlightening but I've unfortunately run into a
    problem.

    The value of hashtag is an array. When I do orderByChild('hashtag') that
    is ordering by array values and when I add .equalTo(hashtag) that is trying
    to compare to a string value. Is there a step in-between here or something
    else I need to do first?

    Thanks,
    Andrey



    On Monday, June 1, 2015 at 5:34:57 PM UTC-4, Michael Kato Wulf wrote:

    Please read the query docs
    <https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries>.
    It's only a couple pages of text and examples, and very enlightening.

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 12:27 PM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Would this work to only return a subset of items based on hashtags? The
    object looks like this:

    things: {
    thingID1: {
    something: 'value';
    },
    thingID2: {
    something: 'value'
    },
    ...}

    I need to load only a subset of things that match the value of
    'something'.


    On Monday, June 1, 2015 at 3:03:13 PM UTC-4, Michael Kato Wulf wrote:

    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to
    filter server-side.
    Right, that's the goal. I need to reduce the data set so that it
    returns only the filtered items. I need an accurate $index in ng-repeat
    because I'm using a module called 'ui-sortable' to drag and drop sort the
    tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue
    and had to sort via the controller instead. Using the regular $filter
    service didn't quite work because it returns an array that is not a
    $firebaseArray which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out
    another solution that added a new method to $extend $firebaseArray runs
    every time the model is changed at all like this: ng-repeat="thing in
    things.filter()" but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey
    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf wrote:

    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to
    filter server-side. If the goal is to filter the content in the view,
    filtering in the ng-repeat, as intended by the Angular code, seems more
    ideal. Any reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    I am trying to filter a $firebaseArray to only load matching
    "hashtag" values. I need to do this from the controller rather than the
    view because I am using a 'ui-sortable' module which is dependent on a
    correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray,
    'hashtag'); because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do not
    quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%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/92ccf236-e8f4-4d8c-85cf-212199a0e78e%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Frank van Puffelen at Jun 2, 2015 at 4:48 pm
    Hey Andrey,

    You would indeed have to programmatically maintain that index. I wouldn't
    use anything Angular-specific for this, since it is pure data manipulation
    and has nothing to do with data display. So I'd either update the index
    from wherever you call set or push, or use a simple server script that
    listen for the relevant child_ events.

    If you feel that extending the AngularFire array may work for your
    use-case, then by all means keep trying that. As Kato said in his initial
    response: we usually make a clear split between filtering that should
    happen on the server vs. client-side filtering. The approach with custom
    indexes I described applies only to server-side filtering. Extending the
    AngularFire array applies only to client-side filtering.

            Frank
    On Tuesday, June 2, 2015 at 8:42:41 AM UTC-7, Andrey Kondratyuk wrote:

    Thanks. To create an "index that maps" would I need to separately run an
    angular.forEach on the main data and then re-save part of it (and keep it
    in sync manually)?

    It seems like I was so closed with the $extend firebaseArray method. It's
    a shame that won't work.
    On Tuesday, June 2, 2015 at 12:12:56 AM UTC-4, Frank van Puffelen wrote:

    Firebase queries compare single values, not arrays. There are currently
    no "contains" or "oneOf" operators.

    If you want to query on something that isn't supported by Firebase's
    built-in query mechanism, you can often get the same result by building
    your own so-called index. The goal of such an index is purely to serve
    whatever need you have.

    I'll provide an example below. Note that I picked just one possible
    use-case, just so we have something concrete. The solution applies equally
    to other Things, Somethings and Values, but I find it easier to explain
    this using less generic terms.

    Say that you have a collection of users and each user can have multiple
    phone numbers.

    users
    twitter:346724367
    name: "Frank van Puffelen"
    phonenumbers
    408123456: true
    622996143: true
    password:63474326
    name: "Andrey Kondratyuk "
    phonenumbers
    213018265: true
    703509211: true

    Now say you want to look up a user by their phone number. You would
    create an index that maps phone numbers to users:

    uid_by_phonenumber
    408123456: twitter:346724367
    622996143: twitter:346724367
    213018265: password:63474326
    703509211: password:63474326

    On this you can do a query with:


    ref.child('uid_by_phonenumber').orderByKey().equalTo(408123456).once('child_added',
    function(snapshot) {
    var uid = snapshot.val();
    ref.child('users').child(uid).once('value',
    function(userSnapshot) {
    var user = userSnapshot.val();
    });
    });

    You could use the same index to check if a phone number has already been
    registered, for example when a new user registers.

    Frank

    On Monday, June 1, 2015 at 8:41:19 PM UTC-7, Andrey Kondratyuk wrote:

    Thanks. That was very enlightening but I've unfortunately run into a
    problem.

    The value of hashtag is an array. When I do orderByChild('hashtag') that
    is ordering by array values and when I add .equalTo(hashtag) that is trying
    to compare to a string value. Is there a step in-between here or something
    else I need to do first?

    Thanks,
    Andrey



    On Monday, June 1, 2015 at 5:34:57 PM UTC-4, Michael Kato Wulf wrote:

    Please read the query docs
    <https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries>.
    It's only a couple pages of text and examples, and very enlightening.

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 12:27 PM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Would this work to only return a subset of items based on hashtags?
    The object looks like this:

    things: {
    thingID1: {
    something: 'value';
    },
    thingID2: {
    something: 'value'
    },
    ...}

    I need to load only a subset of things that match the value of
    'something'.


    On Monday, June 1, 2015 at 3:03:13 PM UTC-4, Michael Kato Wulf wrote:

    Andrey,

    Apply a query to the ref before passing it into AngularFire:

    var ref = new Firebase(...);
    var list = $firebaseArray( ref.orderByChild('foo').limitToFirst(20) );

    Cheers,
    Kato


    On Mon, Jun 1, 2015 at 11:51 AM, Andrey Kondratyuk <and...@dsrp.tv>
    wrote:
    Hey Kato,

    Thanks for the reply.

    If the goal is to reduce the data set, a query should be used to
    filter server-side.
    Right, that's the goal. I need to reduce the data set so that it
    returns only the filtered items. I need an accurate $index in ng-repeat
    because I'm using a module called 'ui-sortable' to drag and drop sort the
    tasks.

    If the goal is to filter the content in the view, filtering in the
    ng-repeat, as intended by the Angular code, seems more ideal. Any reason
    you excluded these two recommended choices?
    I started out filtering in the view but that caused an $index issue
    and had to sort via the controller instead. Using the regular $filter
    service didn't quite work because it returns an array that is not a
    $firebaseArray which seems to be causing binding issues.

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues
    I think I changed to your filter solution between posting that and
    updating the plunker sorry. The main issue I am having now is that I cannot
    get the filter to re-run when I make changes to $scope.hashtag. I made a
    new plunker that better illustrates the issue:
    http://plnkr.co/edit/RUwL0Cstm9c8jhI2VGi9?p=preview

    When you click on the "set hashtag to #something" or "#another" that
    simulates switching to a different tag. If you manually change
    $scope.hashtag in the controller to something else you can see the list
    filter properly. If you click those buttons to switch $scope.hashtag than
    the list does not re-filter.

    I'm not sure if this is helpful but I did eventually figure out
    another solution that added a new method to $extend $firebaseArray runs
    every time the model is changed at all like this: ng-repeat="thing in
    things.filter()" but that seems really wrong.

    Any advice would be much appreciated.

    Thanks,
    Andrey

    On Monday, June 1, 2015 at 10:34:37 AM UTC-4, Michael Kato Wulf
    wrote:
    Hello Andrey,

    If the goal is to reduce the data set, a query should be used to
    filter server-side. If the goal is to filter the content in the view,
    filtering in the ng-repeat, as intended by the Angular code, seems more
    ideal. Any reason you excluded these two recommended choices?

    Also, what's wrong with your attempt? It says in the code that $add
    doesn't work, but it seems to work fine. I'm not seeing any issues.

    Cheers,
    Kato


    On Fri, May 29, 2015 at 10:58 AM, Andrey Kondratyuk <and...@dsrp.tv
    wrote:
    I am trying to filter a $firebaseArray to only load matching
    "hashtag" values. I need to do this from the controller rather than the
    view because I am using a 'ui-sortable' module which is dependent on a
    correct $index.

    I cannot use something like:
    $scope.things = $filter('filter')(unfilteredFirebaseArray,
    'hashtag'); because it returns a new array that is not a $firebaseArray.

    Kato posted a possible solution here:
    https://gist.github.com/katowulf/bee266e31aa60cb0eed6 but I do
    not quite get how this works. Here's my attempt:
    http://plnkr.co/edit/SKN9qG5UoIFtpf2CtKNv?p=preview

    Can anyone please explain how to $filter a firebaseArray?

    --
    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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6e68fb40-1a7b-45ee-837f-c6c8a43d038b%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/5e95dc8d-4e60-4aee-9f95-9e870355487e%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-angul...@googlegroups.com.
    To post to this group, send email to firebase...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/cb202b6c-0292-4089-885e-e897df7bf647%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/4a5b2fd2-e20a-49ce-a85b-57d6008cba44%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedMay 31, '15 at 10:34p
activeJun 2, '15 at 4:48p
posts11
users3

People

Translate

site design / logo © 2021 Grokbase