In my controller I call a factory that returns a JSON object as such:
function getData() {
trainDataFactory.getData()
.success(function (data) {
$scope.dataList = data;
})
.error(function (error) {
$scope.status = 'Unable to load data: ' + error.message;
});
}
I am then able to access $scope.dataList in the view like so (which works):
{{ dataList[0].UnitNumber }}
But I want to access this same variable in the controller however it won't work - angular just breaks.
I try this at the start of the controller:
init();
function init() {
getData();
console.log($scope.dataList[0].UnitNumber);
$scope.firstDataListItem = $scope.dataList[0].UnitNumber;
}
getData() is called so I don't see why $scope.dataList is unavailable??