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;
});
0

1 Answer 1

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;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.