When you allow $ firebaseArray to be returned, do you need to return the firebaseObject service first?

I recently discovered a David East firebase blog post and started migrating my downloaded usage from my controllers to my permissions for each view. One of the problems that came up is when I retrieve $ firebaseArray with firebaseRef that contains something from another firebase database call. My referent for the second part will be something like this:

var chatRef = firebase.database().ref('messages/'+thisGroup.groupId+'/main');

Is this a situation where I can only deploy one promise through a solution, or I close up doing something like this (ActiveGroup is a service that returns a firebaseObject for the currently selected group):

.state('tab.chats-main', {
      url: '/chats/main',
      cache: true,
      views: {
        'tab-chats': {
          templateUrl: 'templates/tab-chatsTopic.html',
          controller: 'ChatsTopicCtrl'
        }
      },
    resolve: {
      currentAuth: authRequire,
      posts: function($firebaseArray, currentAuth, ActiveGroup){
        var thisGroup = ActiveGroup(currentAuth.uid);
          thisGroup.$loaded().then(function(){
          var chatRef = firebase.database().ref('messages/'+thisGroup.groupId+'/main');
          return $firebaseArray(chatRef.limitToLast(100)).$loaded();
        })    
      }
    }
})

And here I entered the messages into the controller:

    .controller('ChatsTopicCtrl', function($scope, thisGroup, posts, profile, chatName, chatMessages, currentAuth, ActiveGroup, $cordovaCamera, $ionicScrollDelegate, $ionicModal, $ionicActionSheet, $timeout,$state, moment) {

console.log("what are posts? ",posts); // posts is undefined

Thanks in advance!

+4
1

, -, , , . firebase ( ), , , :

.state('tab.chats-main', {
  url: '/chats/main',
  cache: true,
  views: {
    'tab-chats': {
      templateUrl: 'templates/tab-chatsTopic.html',
      controller: 'ChatsTopicCtrl'
    }
  },
  resolve: {
    currentAuth: authRequire,
    thisGroup: function(ActiveGroup, currentAuth){
      return ActiveGroup(currentAuth.uid).$loaded();
    },
    posts: function($firebaseArray, thisGroup){     
      var chatRef = firebase.database().ref('messages/'+thisGroup.groupId+'/main');
      return $firebaseArray(chatRef.limitToLast(100)).$loaded();    
    }       
}
})

, :

    .controller('ChatsTopicCtrl', function($scope, thisGroup, posts, profile, chatName, chatMessages, currentAuth, ActiveGroup, $cordovaCamera, $ionicScrollDelegate, $ionicModal, $ionicActionSheet, $timeout,$state, moment) {

console.log("what is posts? ",posts); // gives proper result

/ , .

0

Source: https://habr.com/ru/post/1648695/


All Articles