Ok, I think this if you make these changes it should fix the remaining issues when it wont always load the data.
myApp.factory('markersRepository', function($http){
var markersRepository = {
getAllMarkers: function(){
var url = "main/json_get_markers";
var promise = $http.get(url).then(function(response){
return response.data;
});
return promise;
}
};
return markersRepository;
});
function MapController ($scope, markersRepository){
markersRepository.getAllMarkers().then(function(markerData){
$scope.markers= markerData
});
});
I hope this helps --- Cheers!