angularjs - Need to Loop thru a firebaseArray and returning 1 object -


i trying access data returned in firebase array , return 1 of these objects - firebase array returning 3 objects , want able loop through these 3 objects , compare data. not sure do:

its function getnewsdetail problem.

angular.module('news.services', ['ionic', 'firebase' ]) .factory('newsitems', ['$firebasearray', function($firebasearray){   var newsref = new firebase ('https://xxxx.firebaseio.com/newsitems');        var thenewsitems = [$firebasearray(newsref)];     //alert($firebasearray(newsref).length)     return{     getnewsitems: function(){         return $firebasearray(newsref);     },     getnewsdetail: function(newsid){         for(var = 0; < thenewsitems.length; i++){             if(thenewsitems[i].id == parseint(newsid)){                 return thenewsitems[i];             }         }         return null;     }     };  }]); 

including firebase layout:

      newsitems           -kiip4vmlntvaklobaxa                  detail: "detail y"                  title: "title x"                  id: 0           -kiipatcknu1wzehky9-                 detail: "come down , play us"                 title: "new players welcome"                 id: 1           -kiiphim2nylh_bgg8um                detail: "story 3"                title: "title 3"                id: 2 

when want use single object firebase in angularjs view, use $firebaseobject. so:

getnewsitems: function(){     return $firebasearray(newsref); }, getnewsdetail: function(newsid){     return $firebaseobject(newsref.child(newsid); } 

firebase intelligent enough in loading of data won't reload it, if has in memory.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -