Answer the question
In order to leave comments, you need to log in
Why is Restangular not loading data?
I'm trying to load data using Restangular, as a result, the array in which I save the received data is empty.
Factory
function dataService(Restangular) {
Restangular.setBaseUrl('http://beta.json-generator.com/api/json/get/EkKWgIpZ7?indent=4');
var factory = {
getPostsList: getPostsList
};
return factory;
function getPostsList() {
return Restangular.all('posts').getList();
}
function ExampleCtrl(dataService) {
var self = this;
this.posts = [];
this.getList = getList;
function getList(){
dataService.getPostsList.then(function(posts){
self.posts = posts;
},function(err){
console.log(err);
});
}
console.log(self.posts);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question