How to print object returned by Firebase service as array (to the console)

别来无恙 提交于 2019-12-09 23:31:25

问题


I am using Angular + Firebase stack.

I would like to convert object returned by Firebase:

into the array so it can be printed in the console like this:

 [ {object}, {object}, {object}, {object}, {Object} ];

I know how to use "orderByPriority" filter in template but I don't know how to use it inside controller?


回答1:


If you want to print an array of returned objects to the console, you need to apply orderByPriority filter (as you already found out) and use $watchCollection to watch for changes (as data are returned asynchronously):

    $scope.$watchCollection('messages', function() {
      console.log(orderByPriorityFilter($scope.messages));   
    });  

You can check out the working solution in this Plunker.



来源:https://stackoverflow.com/questions/22322299/how-to-print-object-returned-by-firebase-service-as-array-to-the-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!