Pregunta

I'm retrieving some data from firebase, which gives me an object that looks something like this:

$add: function (item) {
$auth: function (token) {
$bind: function (scope, name, defaultFn) {
$child: function (key) {
$getIndex: function () {
$getRef: function () {
$id: "tasks"
$off: function (type, callback) {
$on: function (type, callback) {
$remove: function (key) {
$save: function (key) {
$set: function (newValue) {
$transaction: function (updateFn, applyLocally) {
$update: function (newValue) {
-JLCrhLLGqp-OZN-9toC: true
-JLCrkqFxxxaV6eG8lrb: true
__proto__: Object

I need to iterate over all the keys that looks like "-JLCrhLLGqp-OZN-9toC".

My question is how is how I do this best? Can I somehow remove the $methods?

Doing this in html is easy with ng-repeat, which seems to figure out what parts to ignore. But I can't figure out how to do it on the controller?

¿Fue útil?

Solución

You could use the angular isFunction function when iterating over the properties:

angular.forEach( $scope.firebaseObject, function(value, key){
  if( !angular.isFunction(value)){
    alert(key + ' is not a function');
  }
});

Fiddle

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top