have a look at this link:
AngularJS access scope from outside js function
you can think of it in a different way, once you have access to the scope, you simply call a setter method inside the controller with the data in your array and then you can do whatever you need. I have used this approach in a project and it works quite well.
example :
//externalScope is a global variable declared in the angular controler
//this is a way to access the controller and trigger methods from outside of angular
//all we want is to signal to angular that some data has been changed so it can do something. in my example selectedUserValue is the data bit I am passing to the controller.
if (externalScope) {
externalScope.$apply(function () {
externalScope.selectUser(selectedUserValue);
});
}
this code lives outside of the controller wherver you try to call the scope method with some data
now in the actual controller we have something like this:
var externalScope;
(function () {
controller code
somewhere in the controller :
externalScope = $scope; //this exposes the scope to the outside world
notice how the externalScope variable is declared outside of the controller so it will be global.
After this just code whatever you need in the angular method that you call from the outside.
in my case it's a setter and then it calls something else which makes use of that data:
$scope.selectUser = function (userID) {
if (userID && userID !== $scope.selectedUserID) {
$scope.selectedUserID = userID;
$scope.loadUserRecords();
}
};
Hope this makes sense. Disclaimer ... This isn't what I call something trivial and should only be used if you really have no other option!