i have 2 services. 1 uses the other to fetch data, this works... After that the service provides a getter and setter for a variable
` .service('ClickHandlers', ['$firebase','FirebaseData',function ($firebase,FirebaseData) { var lastClickedVisitedPlace;
return {
getLastClickedVisitedPlace: function () {
console.log('getLastClickedVisitedPlace service function triggered');
var destinations = FirebaseData.getDestinations();
console.log('service destinations',destinations);
**var defaultVisitedplace = destinations[0];
console.log('service defaultVisitedplace',defaultVisitedplace);
lastClickedVisitedPlace = defaultVisitedplace.id;**
console.log('service lastClickedVisitedPlace',lastClickedVisitedPlace);
return lastClickedVisitedPlace;
},
setLastClickedVisitedPlace:function(id){
console.log('service id',id);
console.log('setLastClickedVisitedPlace service function triggered');
lastClickedVisitedPlace = id;
console.log('service lastClickedVisitedPlace',lastClickedVisitedPlace);
}
};
}])`
the following lines: var defaultVisitedplace = destinations[0]; console.log('service defaultVisitedplace',defaultVisitedplace); lastClickedVisitedPlace = defaultVisitedplace.id; don't seem to work, destinations[0] is undefined, but in the line above saying: var destinations = FirebaseData.getDestinations(); console.log('service destinations',destinations);
i get this as return data in console: destinations [] 0: Object 1: Object 2: Object
so how can i get the first array object .id value like you would normally do with destinations[0].id ??