Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to access the value of a variable which is inside a function in AngularJS inside the view. I know for a matter of fact that if I somehow get the value of the variable in the controller scope. I would be able to get it in the view also.

What I have tried:

<pre>
var app=angular.module("myModule",[]);
    app.controller("myController",function($scope){
        var excelJsonObj=[];
        $scope.data={};
        $scope.uploadExcel=function(){
        var myfile=document.getElementById('file')
        var input=myfile
        var reader=new FileReader();
        reader.onload=function(){
        var filedata=reader.result
        var workbook=XLSX.read(filedata, {type:'binary'});
        workbook.SheetNames.forEach(function(sheetName){
   var rowObject=XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
       excelJsonObj=rowObject;
           });
              var info1=excelJsonObj[0].Birthday
              $scope.data.info=info1

              // Here  I see the value in the console

             console.log($scope.data.info)
            }

            // Here I don't see the value

           reader.readAsBinaryString(input.files[0]);
           if($scope.data.info){
            console.log($scope.data.info)
            }
        };
    })
Posted
Updated 29-Jun-19 5:45am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900