0

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

rawatdeepesh
  • 584
  • 8
  • 31
  • return `$http` promise from factory `get` method..and do `resolve` it in your controller – Pankaj Parkar May 26 '15 at 10:03
  • @pankajparkar :I have already tried it . var deferred = $q.defer(); and then i fetched data and resolved it using deferred.resolve(data.datavalue) or deferred.resolve(data); and then i used promise.then() ;but it passes an object and when i assign the value from that object to my scope variable , it doesn't reflect any changes in my graph controller.Although $scope.mysctrl shows that the data has been inserted in the console.log but the graph doesn't render. – rawatdeepesh May 26 '15 at 10:12
  • See if this helps: http://stackoverflow.com/questions/29880592/why-do-angular-service-private-fields-not-update?lq=1 – Jonathan Smith May 26 '15 at 10:23

0 Answers0