i'm developing a webapp in AngularJS. I've created a service for send json requests and receive json data via post. The service is ok because when i load the page Firebug shows me json's data, but the view doesn't load data.
This is my code
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:'/'});
this is my reportController.js
app.controller("reportController", ['$scope','$log', function($scope, $log, dati){
$scope.rows = dati; }]);
and this is my 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>
also, if i write to log i see "undefined" instead see data on log.
Regards to all.
Davide
You forgot to declare resolved dependency in your array notation. Should be:
app.controller("reportController", ['$scope', '$log', 'dati', function($scope, $log, dati) {
$scope.rows = dati; // note this DI --^
}]);