问题
For some reason im losing scope of ngtable params in my view , everything in ngtableparams is undefined ( i see in angularjs batarang binding ).
my controller code is
this.contractsParams = new ngTableParams({
defaultSort: 'asc',
counts: [],
total: 10, // length of data
getData: function ($defer, params) {
this.MyService.query(
angular.bind( function (data) {
debugger;
$defer.resolve(data.Data);
}));
}
});
also , the getdata is not getting called at all ever.
My View
<table ng-table="controller.contractsParams">
<tr ng-repeat="contract in $data">
<td data-title="'Title'" data-sortable="'Title'">{{contract.Title}}</td>
</tr>
回答1:
The issue of losing scope might be rooted in ngTableParams
initialization, it takes two objects: parameters and settings , have a look in docs.
So the simple initialization look like :
$scope.tableParams = new ngTableParams(
/* parameters */
{
page: 1, // show first page
count: 10 // count per page
},
/* settings */
{
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
Have look in example plunk from official site.
回答2:
Resolved this by adding this piece to my view
ng-controller="myController as controller"
来源:https://stackoverflow.com/questions/26939837/losing-ngtableparam-scope-in-my-view