应该使用从数组中获取的数据填充表。之前的代码已经在其他应用程序上工作,所以我复制了脚本,由于某种原因,数据没有加载。控制台中没有显示错误。错误必须位于未找到的数据中。有什么想法吗?
<tr ng-repeat="x in patents">
<td>{{x.id}} h</td>
<td>{{x.applicationnumber}}</td>
<td>{{x.clientref}}</td>
<td>$ {{x.costtorenew}}</td>
<td>{{x.renewalduedate}}</td>
<td><button type="button" class="btn btn-danger" ng-click="remove(x.id)">Remove</button></td>
</tr>
var app = angular.module('myApp', ['ngRoute', 'angularMoment']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when('/list-patents', {
templateUrl: '/templates/list-patents.htm',
controller: 'patentCtrl'
})
app.controller('patentCtrl', ['$scope', '$http', 'loadPatents', function($scope, $http, loadPatents) {
var self = this;
self.patent={id:null,applicationnumber:'',clientref:'',costtorenew:'',renewalduedate:'',basketstatus:''};
self.patents=[];
self.remove = remove;
fetchAllPatents();
function fetchAllPatents(){
loadPatents.fetchAllPatents()
.then(
function(d) {
self.patents = d;
},
function(errResponse){
console.error('Error while fetching Users');
}
);
console.log(self.patents)
}
}]);
app.factory('loadPatents', function($http, $q) {
var factory = {};
var REST_SERVICE_URI = 'http://localhost:8080/Sprint002b/restpatent/';
factory.fetchAllPatents = function() {
var deferred = $q.defer();
$http.get(REST_SERVICE_URI)
.then(
function (response) {
deferred.resolve(response.data);
},
function(errResponse){
console.error('Error while fetching Users');
deferred.reject(errResponse);
}
);
return deferred.promise;
}
return factory;
})
答案 0 :(得分:1)
您在视图中没有使用controllerAs,请尝试下面的代码,如果您在控制器中获取数据,那么这将起作用。
<body ng-controller="patentCtrl as p">
<tr ng-repeat="x in p.patents">
<td>{{x.id}} h</td>
<td>{{x.applicationnumber}}</td>
<td>{{x.clientref}}</td>
<td>$ {{x.costtorenew}}</td>
<td>{{x.renewalduedate}}</td>
<td><button type="button" class="btn btn-danger" ng-click="remove(x.id)">Remove</button></td>
</tr>
</body>