Losing ngtableparam scope in my View

2019-08-03 01:49发布

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>

2条回答
可以哭但决不认输i
2楼-- · 2019-08-03 02:17

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.

查看更多
SAY GOODBYE
3楼-- · 2019-08-03 02:17

Resolved this by adding this piece to my view

ng-controller="myController as controller"

查看更多
登录 后发表回答