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:

https://docs.angularjs.org/guide/scope

https://docs.angularjs.org/api/ng/service/$rootscope


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -