1
該表格應填入從數組中取得的數據。之前的代碼已經在其他應用程序上工作過,所以我複製了該腳本,並且出於某種原因數據未加載。控制檯中沒有顯示錯誤。錯誤必須存在於未找到的數據中。任何想法爲什麼?ng-repeat不填充表格數據
<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;
})
您在視圖中我沒有使用controllerAs語法。 – SaiUnique
在你的控制器中,你正在獲取數據。對? – Rakeschand
嘗試'
回答
你不是在你的視圖中使用controllerAs,試試下面的代碼,如果你要數據控制器比這將正常工作。
來源
2017-05-25 13:06:56 Rakeschand
Ahhhh正確的方向。所以如果控制器正在接收數據,我需要使用controllerAs?它正在加載內容(如按鈕),但不是數據本身 –
是的,內容會因爲靜態內容而加載。你可以通過在你的控制器中使用$ scope來代替'self(var self = this;)'來檢查,那麼它也可以工作 – Rakeschand
不,它是我的屬性名稱在JSON文件中。現在全部排序。感謝您的時間!我會在一分鐘內接受 –
相關問題