2017-02-07 4 views
0

ngTableとangularJSを使用しようとしています。AngularJS ngTableがhttp呼び出しを使用してgetDataメソッドを起動しない

私はすべての角度のスタッフをインストールし、それはうまく動作します。

今、ngTableを使用する必要があります。

私は次のコードを使用していますが、私のhttp getは決して引き起こされません。

私はここで何が欠けていますか?

マイコード:

angular.module('clinang', ['ngTable']).controller('pacientesCtrl', function($scope,$http,NgTableParams){ 
 
    this.tableParams = new NgTableParams({ 
 
    page: 1, 
 
    count: 10 
 
    }, { 
 
    getData: function($defer, params) { 
 
     $http.get('/getdadospac/?oper=S', {params: { 
 
     pageNumber:params.page() - 1, 
 
     rangeStart:rangeStart, 
 
     rangeStop:rangeStop}}) 
 
     .then(function(data, status) { 
 

 
     params.total(data.results.total); 
 

 
     $defer.resolve(data.results); 
 
     }); 
 
    } 
 
    }); 
 

 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<link rel="stylesheet"; href="https://unpkg.com/[email protected]/bundles/ng-table.min.css"> 
 
<script src="https://unpkg.com/[email protected]/bundles/ng-table.min.js"></script> 
 
<body ng-app="clinang"> 
 
    <div ng-controller="pacientesCtrl"> 
 
    <a class='btn btnprimary' href='/getdadospac/?oper=S' >Button</a> 
 
    <table ng-table="vm.tableParams" class="table" show-filter="true"> 
 
     <tr ng-repeat="paciente in $data"> 
 
     <td title="'Pront'" filter="{ name: 'text'}" sortable="'pront'"> 
 
      {{paciente.pront}}</td> 
 
     <td title="'Nome'" filter="{ age: 'number'}" sortable="'nome'"> 
 
      {{paciente.nome}}</td> 
 
     </tr> 
 
    </table> 
 
    </div> 
 
</body>

+0

body'/'html'タグ –

+0

'上 'NG-アプリ= "clinang"'また、私はngTableを知らないが、私は、あなたがたgetData(と呼ばれる関数を定義することを奇妙ました)しかしあなたのコードで呼び出されることはありません(たぶんngTable機能です)。 – Tonio

+0

@Pankaj Parkar ng-appを定義しました。私は簡潔さのために投稿していません。 –

答えて

1

あなたがコントロールの作成後reload()メソッドを使用している場合は、それが作業をつもり。

.successも使用していますが、$httpの場合は.thenメソッドを使用する必要があります。

私はdebuggerコールをgetDataの中に入れています。DevToolsを開くと、それが実行されることがわかります。

angular.module('clinang', ['ngTable']).controller('pacientesCtrl', function($scope,$http,NgTableParams){ 
 
    this.tableParams = new NgTableParams({ 
 
    page: 1, 
 
    count: 10 
 
    }, { 
 
    getData: function($defer, params) { 
 
    debugger; 
 
     $http.get('/getdadospac/?oper=S', {params: { 
 
     pageNumber:params.page - 1}}) 
 
     .then(function(data, status) { 
 

 
     params.total(data.results.total); 
 

 
     $defer.resolve(data.results); 
 
     }); 
 
    } 
 
    }); 
 
    this.tableParams.reload(); 
 

 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<link rel="stylesheet"; href="https://unpkg.com/[email protected]/bundles/ng-table.min.css"> 
 
<script src="https://unpkg.com/[email protected]/bundles/ng-table.min.js"></script> 
 
<body ng-app="clinang"> 
 
    <div ng-controller="pacientesCtrl"> 
 
    <a class='btn btnprimary' href='/getdadospac/?oper=S' >Button</a> 
 
    <table ng-table="vm.tableParams" class="table" show-filter="true"> 
 
     <tr ng-repeat="paciente in $data"> 
 
     <td title="'Pront'" filter="{ name: 'text'}" sortable="'pront'"> 
 
      {{paciente.pront}}</td> 
 
     <td title="'Nome'" filter="{ age: 'number'}" sortable="'nome'"> 
 
      {{paciente.nome}}</td> 
 
     </tr> 
 
    </table> 
 
    </div> 
 
</body>

+0

Okですが、params.pageのエラーは何ですか? –

+0

あなたはそのオブジェクトを渡す必要がありますので、内部に見えます – andrepaulo

+0

大丈夫、ありがとうございます。 –

関連する問題