2016-03-24 6 views
1

私はAngularJSでWebアプリケーションを開発しています。私は、jsonリクエストを送信し、jsonデータを投稿経由で受信するサービスを作成しました。 Firebugは私にjsonのデータを表示しますが、ビューはデータをロードしないので、サービスはOKです。AngularJSサービスはOKですがデータなし

これは、これは私のreportController.js

app.controller("reportController", ['$scope','$log', function($scope, $log, dati){ 
    $scope.rows = dati; }]); 

であると私は、私をログに書き込む場合、これは、また私のreportV.html

<div class="col-md-8"> 
    <table class="table table-striped"> 
     <thead> 
      <tr> 
       <th>Code</th> 
       <th>Surname</th> 
       <th>Name</th> 
      </tr> 
     </thead> 
     <tbody ng-repeat="row in rows"> 
      <tr> 
       <td>{{row.code}}</td> 
       <td>{{row.surname}}</td> 
       <td>{{row.name}}</td> 
      </tr> 
     </tbody> 
    </table> 
</div> 

である私のコード

var app = angular.module('MyApp', ['ngRoute']); 

    app.service('selectSrv',['$http', function($http){ 
     this.select = function(tab, fields){ 
       $http.defaults.headers.post["Content-type"] = "application/json"; 
       return $http.post('/loader',{posttab:tab, postfields:fields}) 
         .success(function(data){ 
          return data; }); 
      }; 
    }]); 
    app.config(['$routeProvider',function($routeProvider){ 
     $routeProvider 
      .when("/report",{ 
          templateUrl:"/reportV.html", 
          controller:"reportController", 
          resolve:{ 
            dati: function(selectSrv){ 
             return selectSrv.select(table,["col1","  }; 
}]); 
col2","col3"]); } 
          } }) 
      .otherwise({redirectTo:'/'}); 

です「undefined」を参照してください。代わりにログのデータを参照してください。

よろしくお願いいたします。

Davide

答えて

0

あなたの配列表記で解決済みの依存関係を宣言するのを忘れました。すべきである:

app.controller("reportController", ['$scope', '$log', 'dati', function($scope, $log, dati) { 
    $scope.rows = dati;    // note this DI --^ 
}]); 
+0

ooppss。ありがとう@dfsqあなたは正しいですが、今私は圧縮された空の表を参照してください..... – dpope

+0

さて、それは動作します。私はそれが必要なのか分からないdati.data 楽しむ – dpope

+0

$ httpサービスは実際の応答データを何かにラップする必要があるので、 'data'プロパティを宣言するので、$ httpサービスはレスポンスオブジェクトを返します。あなたの場合、 'success'の代わりに' .then(function(response){return response.data;}) 'を使います。それが役に立ったら答えを受け入れることを忘れないでください。 – dfsq

関連する問題