angularjs - using data from a promise in an angular controller -
inside of controller calling service contains array of data work in drinklibrary
.drinklibrary
has getdrinks
-method getting data database.
app.controller('analysiscontroller',function(drink,drinklibrary,$scope){ console.log('connected'); var drinkset = function(){ drinklibrary.getdrinks().success(function(data){ var caffeinedata = data; }); }; drinkset(); });
when call success()
getting data want inside of caffeinedata
. when call drinkset()
getting data need inside of browser console. in controller. however, limited caffeinedata
exist inside of drinkset
-method.
is there better way set might able use data in chart?
where want data
available? there number of things can do. example:
app.controller('analysiscontroller',function(drink,drinklibrary,$rootscope,$scope){ console.log('connected'); var drinkset = function(){ drinklibrary.getdrinks().success(function(data){ var caffeinedata = data; // local function $scope.caffeinedata = data; // local controller $rootscope.caffeinedata = data; // local application }); }; drinkset(); });
references:
Comments
Post a Comment