javascript - store $http GET promise object locally -


i've been scratching head trying figure out how implement simple data update on graph due lack of angular service knowledge. trying make 1 request , store json object locally on controller can have (1) original json render original chart , (2) modified json based on user input (always modifies original json) render updated chart. here controller:

`

angular.module('scattchartapp') .controller('chartctrl', function($scope, $http, $cachefactory) {    $http.get('chartconfig.json').success(function(response) {     $scope.options = response.options;     $scope.data = response.data;     $scope.initdata = angular.copy($scope.data);   });      $scope.update = function(user){     var a, b, c, d, e;     = user.a; b = user.b; c = user.c; d = user.d; e = user.e;     var data = $scope.data;     if(a !== "" && b !== "" && c !== "" && d !== "" && e !== ""){       for(var = 0; i<$scope.data.length; i++){           for(var j = 0; j<$scope.data[i].values.length; j++){               var x = $scope.data[i].values[j].x;               var y = $scope.data[i].values[j].y;               var z = $scope.data[i].values[j].size;               data[i].values[j].x = a*x + b*y;               data[i].values[j].y = c*x + d*y;               data[i].values[j].size = e*e*z;           }       }       $scope.$apply();     }   };    $scope.reset = function(){      $scope.user = {};     $scope.data = angular.copy($scope.initdata);     $scope.$apply();   };   });` 

this plunker (which if make proper input , press update scale accordingly 1 time , rest won't work): http://plnkr.co/edit/n4bdl7lyoylw5twbra6g?p=preview

removing $scope.$apply() should solve problem.

since functions using here come angularjs framework, don't have use $scope.$apply(). in fact it's making application crash. that's why it's working once.

for more informations $scope.$apply()angulardoc

edit: it's possible need set plugin option refreshdataonly false.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -