I have a factory
which provides me a promise when getting a json file :
myapp.factory('topAuthorsFactory', function($http, $q) {
var factory = {
topAuthorsList: false,
getList: function() {
var deffered = $q.defer();
$http.get('../../data/top_10_authors.json')
.success(function(data, status) {
factory.topAuthorsList = data;
}).error(function(data, status) {
deffered.reject('There was an error getting data');
});
return deffered.promise;
}
};
return factory;
});
and in my controller
I want to display the content of the json
file on my console as the following :
myapp.controller('topAuthorsController', function($scope, topAuthorsFactory) {
$scope.listAuthors = topAuthorsFactory.getList().then(function(topAuthorsList) {
$scope.listAuthors = topAuthorsList;
console.log('Testing...');
}, function(msg) {
alert(msg);
});
console.log($scope.listAuthors);
}
but in my console I'm getting this :
so how can I solve this ? and why I dont see the message "testing..." in console ?