How can I assign value to an array from an async function and use it outside the scope of said function?
Basically I have a factory that randomizes values in an array, so I can attach images randomly to divs.
$scope.Resources = ResourceFetch.getResource().then(function(resources){
$scope.img1 = JSON.stringify(resources.img1);
$scope.img2 = JSON.stringify(resources.img2);
$scope.img3 = JSON.stringify(resources.img3);
$scope.img4 = JSON.stringify(resources.img4);
var myArray = [$scope.img1, $scope.img2, $scope.img3, $scope.img4];
console.log('myArray is ' + myArray); // <- Fine.
var shuffledArray = [];
ShuffleArray.getShuffled(myArray).then(function(array){
shuffledArray = array;
console.log('Shuffled array is ' + array); // <- Fine.
console.log('Shuffled array again ' + shuffledArray); // <- Fine
});
console.log('Shuffled array outside is ' + shuffledArray); // <- Nothing.
});