I am having a problem that my $scope.todo list always returns a undefined when using the angular function ng-repeat. If I define the $scope.todo it works perfectly but when I use the solution below to fetch results and add it to the variable I get an undefined before it seems to have a chance to go and retrieve the correct values
I have now added a bit better code to explain my problem. After looking at some of the jsfiddles below and trying those solutions I'm starting to think its something to do with my callbacks.
function TodoCtrl($scope) {
$scope.todos = [];
buildInitialList(function (result){
console.log(result); //Logs defined after the undefined below
$scope.todos = result;
});
console.log($scope.todos); //Logs undefined before the defined log above
}
function buildInitialList(callback){
//Simulates call to db
setTimeout(function (){
callback([{text: 'item 1', done: false},
{text: 'item 2', done: false}]);
},2000);
}
function fetch(url, callback) {
$.getJSON(url, function (data, status) {
callback(data);
});
}