I am pretty new to angularfire but I am trying to create an array that is a list of names from a firebase array. When I look at what lists returns it seems to be what I want, so I know the function is working correctly.
angular.module('myApp')
.factory('QuestionType', function ($firebaseArray, $firebaseObject, Ref) {
var types = $firebaseArray(Ref.child('questionTypes'));
var questionType = {
list: function(){
var lists =[];
types.$loaded().then(function(){
for(var i=0; i<types.length; i++){
lists.push(types[i].name);
}
return lists;
});
}
};
return questionType;
});
In my controller I call that factory but because it is asynchronous, when I try and use the array in my view, it comes back as undefined.
$scope.questionType = QuestionType.list();
I figured out that I need to use $loaded.then in my factory, but how do I do a similar thing in my controller so that I can properly use it in my view?
Thanks!