I am trying to get a controller to retrieve its data from the server when it comes in to uses but for some reason this doesn't see to work properly:
app.controller('eventListController', ['$scope', '$http', '$routeParams', function ($scope, $http, $routeParams) {
var eventList = this,
getEventList = function () {
var promise = $http.get('../json/Login.json');
promise.then(function (response) {
eventList = response.data;
}, function (error) {
window.alert('Error' + error);
});
};
getEventList();
}]);
It seems pretty straightforward but eventList doesn't load correctly
What I am doing wrong ?
Here is roughly what the JSON looks like
{
"eventHead": [
{
stuff stuff
},
{
more stuff
}
],
"success": true
}
if i do a
window.alert(eventList);
after the
getEventList();
I get [object Object], which seems normal
but if I do
window.alert(eventList.success);
I get undefined
and furthermore my data just doesn't load into the page