Hi,


I want to remove some items within an ng-repeat and I did this with splice.


As in AngularFire docs, this is not recommended and I don't how to do this.


*LIVE DEMO*: *http://jsfiddle.net/adyz/obfrraw9/*

*HTML*
<ul ng-app="myApp" ng-controller="Ctrl">
     <div ng-repeat="card in myCards">

     <li ng-repeat="item in card">
         <h2>Block: {{item.name}} <a href="#{{item.name}}" ng-click=
"removeNode(item,card)">Remove</a></h2>


         <ul ng-if="item.name == 'brands'">
             <li ng-repeat="brandBlock in item.brand_blocks">
                 <h3>Brand: {{brandBlock.name}} <a href=
"#{{brandBlock.name}}" ng-click="removeNode(brandBlock,item.brand_blocks)">
Remove</a></h3>
                 <ul>
                     <li ng-repeat="product in brandBlock.products">
                         <h4>Product: {{product.title}} <a href=
"#{{product.title}}" ng-click="removeNode(product,brandBlock.products)">
Remove</a></h4>
                         <input type="text" ng-model="product.title" ng-blur=
"myCards.$save(card)">
                     </li>
                 </ul>
             </li>
         </ul>
         </li>
     </div>
</ul>

*JS*
angular.module('myApp', ['firebase'])
     .controller('Ctrl', function($scope, $firebase) {

         var mainRef = new Firebase("https://gigi.firebaseio.com/");
         var appRef = mainRef.child('app/-JWKrTGgSd6xoBUwPAsg');
         var sync = $firebase(appRef);
         var syncArray = sync.$asArray();
         $scope.myCards = syncArray;

         $scope.removeNode=function(item,parent){
             parent.splice(parent.indexOf(item), 1); //This is not
recommended, but how? (It does give me some problems)

         };

     }); //End Controller




Thank you,
Adrian



--
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/ec596f48-4721-4e97-a684-3393cd245018%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael Wulf at Sep 16, 2014 at 7:04 pm
    Adrian,

    What problems did you have with parent.$remove(item), in accordance with
    the docs
    <https://www.firebase.com/docs/web/libraries/angular/guide.html#section-arrays>
    ?
    On Mon, Sep 15, 2014 at 8:05 AM, Adrian Florescu wrote:

    Hi,


    I want to remove some items within an ng-repeat and I did this with splice.


    As in AngularFire docs, this is not recommended and I don't how to do this.


    *LIVE DEMO*: *http://jsfiddle.net/adyz/obfrraw9/
    <http://jsfiddle.net/adyz/obfrraw9/>*

    *HTML*
    <ul ng-app="myApp" ng-controller="Ctrl">
    <div ng-repeat="card in myCards">

    <li ng-repeat="item in card">
    <h2>Block: {{item.name}} <a href="#{{item.name}}" ng-click=
    "removeNode(item,card)">Remove</a></h2>


    <ul ng-if="item.name == 'brands'">
    <li ng-repeat="brandBlock in item.brand_blocks">
    <h3>Brand: {{brandBlock.name}} <a href=
    "#{{brandBlock.name}}" ng-click="removeNode(brandBlock,item.brand_blocks)"
    Remove</a></h3>
    <ul>
    <li ng-repeat="product in brandBlock.products">
    <h4>Product: {{product.title}} <a href=
    "#{{product.title}}" ng-click="removeNode(product,brandBlock.products)">
    Remove</a></h4>
    <input type="text" ng-model="product.title"
    ng-blur="myCards.$save(card)">
    </li>
    </ul>
    </li>
    </ul>
    </li>
    </div>
    </ul>

    *JS*
    angular.module('myApp', ['firebase'])
    .controller('Ctrl', function($scope, $firebase) {

    var mainRef = new Firebase("https://gigi.firebaseio.com/");
    var appRef = mainRef.child('app/-JWKrTGgSd6xoBUwPAsg');
    var sync = $firebase(appRef);
    var syncArray = sync.$asArray();
    $scope.myCards = syncArray;

    $scope.removeNode=function(item,parent){
    parent.splice(parent.indexOf(item), 1); //This is not
    recommended, but how? (It does give me some problems)

    };

    }); //End Controller




    Thank you,
    Adrian



    --
    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/ec596f48-4721-4e97-a684-3393cd245018%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/ec596f48-4721-4e97-a684-3393cd245018%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/CAFHX4%3DrAvF9G_GEoZB%3DVLzfGB-AyrgnfZa%2BWCBwyURw%3DNfP1nQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedSep 16, '14 at 6:38p
activeSep 16, '14 at 7:04p
posts2
users2

2 users in discussion

Adrian Florescu: 1 post Michael Wulf: 1 post

People

Translate

site design / logo © 2021 Grokbase