Javascript ng重复不填充表数据
应使用从数组中获取的数据填充该表。以前的代码在其他应用程序上也可以使用,所以我复制了脚本,由于某些原因,数据没有加载。控制台中未显示任何错误。错误一定在于找不到数据。你知道为什么吗Javascript ng重复不填充表数据,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,应使用从数组中获取的数据填充该表。以前的代码在其他应用程序上也可以使用,所以我复制了脚本,由于某些原因,数据没有加载。控制台中未显示任何错误。错误一定在于找不到数据。你知道为什么吗 <tr ng-repeat="x in patents"> <td>{{x.id}} h</td> <td>{{x.applicationnumber}}</td> <td>{{x.clientref}}</td&g
<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>
在您的视图中并没有使用Controllera,请尝试下面的代码,若您在控制器中获取数据,这将起作用
<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>
{{x.id}}h
{{x.applicationnumber}
{{x.clientref}}
${x.costtorenew}
{x.renewalduedate}
去除
我认为您在视图中没有使用controllerAs语法。在您的控制器中,您正在获取数据。对吗?请尝试
,因为您需要在某个地方定义控制器,如路由器或ng控制器内部,否则这将无法朝正确的方向前进。如果控制器正在接收数据,我需要使用controllerAs?它正在加载内容(如按钮),但本身不加载数据是的,内容将加载,因为它是静态内容。您可以在控制器中使用$scope来代替self(var self=this;)
进行检查,然后它也会起作用,因为JSON文件中只有我的属性名。现在都整理好了。谢谢你抽出时间!我马上就接受。很好的一天。
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;
})
<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>