i discovered david east's firebase blog post , have started move $loaded usage controllers resolves each view. 1 issue has come involves situation i'm retrieving $firebasearray firebaseref contains firebase database call. ref second part this:
var chatref = firebase.database().ref('messages/'+thisgroup.groupid+'/main');
is situation can unwrap 1 promise through resolve, or close doing (activegroup service returns $firebaseobject of user's 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 injecting posts in controller:
.controller('chatstopicctrl', function($scope, thisgroup, posts, profile, chatname, chatmessages, currentauth, activegroup, $cordovacamera, $ionicscrolldelegate, $ionicmodal, $ionicactionsheet, $timeout,$state, moment) { console.log("what posts? ",posts); // posts undefined
thanks in advance!
so found works i'm not sure if it's best practice. doing each firebase call separately (and in proper order), seems trick:
.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(); } } })
and controller inject it:
.controller('chatstopicctrl', function($scope, thisgroup, posts, profile, chatname, chatmessages, currentauth, activegroup, $cordovacamera, $ionicscrolldelegate, $ionicmodal, $ionicactionsheet, $timeout,$state, moment) { console.log("what posts? ",posts); // gives proper result
if there better/more recommended way of doing this, i'd still appreciate hearing it.
Comments
Post a Comment