Search code examples
javascriptangularjsangularjs-scopeglobal-variablesjavascript-objects

How to pass array values from javascript to angularjs controller


I am trying to pass values which I am getting from an array from JavaScript file and pushing it to angularJS by using a global variable

In angular file, I am trying to get those values by accessing global variable like but it returns me undefined however I ran

How can I access this values in my controll


Solution

  • Global variables is not a good idea, maybe you need to interact with another web or framework.

    Is you should ouse a global variable, you can declare with a special script in index.html

    <script type="text/javascript">    
     let globalarray; 
    </script>
    

    You also could asign the globalarray to a property of window

    window.globalarray
    

    Or $rootScope.