1

How do I incorporate an existing javascript list of objects into angularjs so that I can then use it in the controller?

var list = [];
var rows = document.querySelectorAll("tr");
for (var i = 0; i < rows.length; i++) {
  var obj = {
    date: rows[i].childNodes[0].innerText,
    action: rows[i].childNodes[1].innerText,
    ao: rows[i].childNodes[2].innerText
  };
  list.push(obj);
}

var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {
  $scope.list = list;
});
Eddie
  • 26,593
  • 6
  • 36
  • 58
jaysonn
  • 105
  • 9

1 Answers1

0

You can access global javascript variable using $window

var list = ...; // GLOBAL var

var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http, $window) {
  $scope.list = $window.list;
});
Bilal Siddiqui
  • 3,579
  • 1
  • 13
  • 20