I would suggest using a service. A service in AngularJS is a singleton - meaning, that the same instance can be injected throughout the app.
This is better than the alternative of using the $rootScope, since it "pollutes" the scope and also does not lend itself to ease of testing with mocked injectables. It's hardly any better than using a global variable.
You could just create an injectable value that contains that array:
app.value("AVal", []);
and that would be enough. Of course, if you created a service, it would allow you to abstract away the details of the data structure:
app.factory("ASvc", function(){
var a = [];
return {
add: function(val){
a.push({v: val})
},
pop: function(){
var item = a.splice(a.length - 1, 1);
return item[0].v || null;
}
};
});
However you choose to do this, both are available as injectables, for example:
app.controller("MainCtrl", function($scope, AVal, ASvc){
AVal.push({v: 5});
// or
ASvc.add(5);
});