I am trying to fetch some data from a url , which returns data in Json format.I am using AngularJS Factories to do the same .Here is my what I am trying to do:
Service.js
angular.module('demoService',[]).factory('samplefactory',function($http){
var factory={};
var gaugeData = {
maxValue: 5000,
animationSpeed: 100,
val: 5000
};
console.log(gaugeData);
factory.get = function()
{
$http.get('http://myurl').success(function(data) {
gaugeData.val = data.data.Tweets[0].FAVOURITE_COUNT;
//return gaugeData;
console.log(gaugeData);// shows the changed values in console
});
}
factory.list = function () {
return gaugeData;
}
return factory;
})
and Here is how I am trying to call it in my controller:
Controller.js
console.log($scope);
return $scope.gaugeHome ={
gaugeData:
samplefactory.get(),
gaugeOptions: ........
I get the data in the console but it doesn't return gaugeData with the changed values . Could there be done something to achieve the same.
Thanks in Advance