Losing ngtableparam scope in my View

不问归期 提交于 2019-12-13 17:43:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!