0

I must be missing something here, but why isn't my table loading with data using Ng-table? I tried following a example but it wont work for me.

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example105-production</title>
<link href="style.css" rel="stylesheet" type="text/css">


<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-table/0.8.3/ng-table.js"></script>
<script src="script.js"></script>



</head>
<body ng-app="test">
<div ng-controller="ExampleController">
<table ng-table="tableParams">
            <thead>
            <tr>
            <th>Name</th>
            <th>Age</th>
            </tr>
            </thead>
            <tr ng-repeat="row in $data">
                <td>{{row.name}}</td>
            </tr>
        </table>
</div>
</body>
</html>

(function(angular) {
'use strict';
angular.module('test', ['ngTable'])
.controller('ExampleController', ['$scope', function($scope) {

        var data = [{ name: "Moroni", age: 50 }, {name: "Moroni2", age: 502        }];
        this.tableParams = new NgTableParams({}, { dataset: data });

  }]);
})(window.angular);

PLUNKR

1
  • You never defined NgTableParams. Commented Mar 17, 2016 at 12:11

3 Answers 3

1

You forgot to inject in your controller: NgTableParams.

And in dataset change to data as example:

$scope.table = new NgTableParams({}, { data: data });

See your example in plunker: http://plnkr.co/edit/b95EjalSTLd70YuB3ZHH?p=preview

Sign up to request clarification or add additional context in comments.

Comments

0

2 changes needed here:

1) Put the data on the scope of the controller to share with the view:

$scope.data = [{name: 'Mor .....;

2) Use the name of the scope variable (data) in the html

<tr ng-repeat="row in data">

Comments

0

Make this change controller

   $scope.data = [{ name: "Moroni", age: 50 }, {name: "Moroni2", age: 502        }];

//   this.tableParams = new NgTableParams({}, { dataset: data });

and use

   ng-repeat="row in data"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.