I am trying to return a value from my AngularJs service to my controller where ever I pass it inside the controller.It does pass the object and also log the data in the console. Here is my code:
angular.module('demoService',[])
.factory('myService',
function($http) {
return {
getAll: function (items) {
var path = "http://enlytica.com/RSLivee/rest/census"
$http.get(path).success(function (items) {
console.log(items.Tweets[1].FAVOURITE_COUNT);
});
}
}
});
How do i return the "items.Tweets[1].FAVOURITE_COUNT" on function call.
Thanks in advance
You can create a promise of the data queried, by using the method then , getAll will know what to do before the response of the API.
angular.module('demoService')
.factory('myService', ['$http',
function ($http) {
function getAll (items) {
var path = "http://enlytica.com/RSLivee/rest/census"
return $http.get(path).then(
function (res) {
return res;
});
}
return {
getAll: getAll;
}
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With