ps0604
ps0604

Reputation: 1071

Converting table from HTML to Javascript array in AngularJS

This plunk is my attempt to convert an HTML table to a Javascript array using only AngularJS/jqLite. I can get the head and body from the table, however when I try to get the rows from the body object I get the following error (see the console): tbody.children is not a function. How to fix this?

Javascript

      var table = angular.element($scope.t);
      var thead = table.children()[0];
      var tbody = table.children()[1];

      console.log(tbody.children());

Upvotes: 0

Views: 40

Answers (1)

mehulmpt
mehulmpt

Reputation: 16547

I've not used this API before, but a quick check reveals that you lose the angular.element benefits when you pick the children(). You can wrap it again like this to access children method again:

  var table = angular.element($scope.t)
  var thead = angular.element(table.children()[0])
  var tbody = angular.element(table.children()[1])

  console.log(tbody.children());

Upvotes: 2

Related Questions