0

I am populating a java script array with values and when I try to access them I am getting undefined array. Does the array have different scope or? In the first console.log the array is OK in the second is undefined.

var pdfEditArray = new Array();


$scope.previewPdf = function () {
    getForamatedPdf(fileName, $scope.pdfVertical, $scope.pdfHorisontal, $scope.pdfControl.ControlText).then(function (response) {
        pdfEditArray.push({ pdfId: '1', controlId: '2', pageNumber: '3', vertical: '4', horisontal: '5' });
    })
    console.log(pdfEditArray);
}


$scope.savePdfFormat = function (pdfEditArray) {
    console.log(pdfEditArray);
}
  • 1
    You override the global pdfEditArray trough using it as argument, simply leave that away... – Jonas Wilms Jan 17 '17 at 16:43
  • Are they in the same controller? If pdfEditArray isn't defined in the same controller for the save as the preview you will need a service to pass the var around – scrappedcola Jan 17 '17 at 16:43
  • 3
    The `pdfEditArray` in the `$scope.savedPdfFormat` function is local scope because it is passed in as an argument. So the global variable does not matter there, only the passed-in argument. – Dan Lowe Jan 17 '17 at 16:43
  • Thank you Jonas . This solved my problem. –  Jan 17 '17 at 16:47

0 Answers0