I've been working on updating my code to ES6. Specifically, I'm using angular-meteor and ng-table. Everything was displaying correctly in the table before the refactor, but now after converting to ES6 syntax, the data no longer appears. Here is a portion of the new code:
class MyController {
constructor($scope, $reactive, NgTableParams, MyService) {
'ngInject';
$reactive(this).attach($scope);
this.subscribe('myCollection');
this.myService = MyService;
this.helpers({
items() {
return this.myService.getItems();
},
itemTableParams() {
const data = this.getReactively('items');
return new NgTableParams({
page: 1,
count: 10
}, {
total: data.length,
getData: (params) => {
// not called
}
});
}
});
}
}
class MyService {
getItems() {
return MyCollection.find({}, {
sort: {
dateCreated: -1
}
});
}
}
export default angular.module('MyModule', [angularMeteor, ngTable, MyService])
.component('MyComponent', {
myTemplate,
controllerAs: 'ctrl',
controller: MyController
})
.service('MyService', MyService);
The const data
variable gets populated, however, the getData
function isn't being triggered. The table in the template is utilizing ctrl.itemTableParams
for the value of the ng-table
attribute, with item in $data
for the ng-repeat
.
Any insights into why the getData
function isn't executing? Your help would be greatly appreciated. Thank you!
P.S.
I've noticed that if I set NgTableParams
to a const tableParams
, and then call the reload()
function, the getData
function does get triggered. However, the data still doesn't appear on the table. This is how I'm setting up the table:
itemTableParams() {
const data = this.getReactively('items');
const tableParams = new NgTableParams({
page: 1,
count: 10
}, {
total: data.length,
getData: (params) => {
}
});
tableParams.reload(); // triggers the getData function
return tableParams;
}
<table ng-table="ctrl.itemTableParams">
<tr ng-repeat="item in $data track by $index">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.dateCreated}}</td>
</tr>
</table>
Even though I see items in the getData
log, the data is still not rendering in the table.