Inside of my controller I am calling my service that contains an array of data that I would like to work with in DrinkLibrary
.DrinkLibrary
has a getDrinks
-method that is getting the data from my database.
app.controller('analysisController',function(Drink,DrinkLibrary,$scope){
console.log('connected');
var drinkSet = function(){
DrinkLibrary.getDrinks().success(function(data){
var caffeineData = data;
});
};
drinkSet();
});
When I call success()
I am getting the data that I want inside of caffeineData
. When I call drinkSet()
I am getting the data that I need inside of my browser console. In the controller. However, I am limited to caffeineData
exist inside of the drinkSet
-method.
Is there a better way to set this up so that I might be able to use this data in a chart?
Where do you want the
data
to be available? There are a number of things you can do. For example:References:
https://docs.angularjs.org/guide/scope
https://docs.angularjs.org/api/ng/service/$rootScope