AngularJS ng-repeat 不显示表格数据 [英] AngularJS ng-repeat is not showing table data
本文介绍了AngularJS ng-repeat 不显示表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的控制器从 spring 应用程序数据中获取数据,但它没有显示在表单中.当我将常量放入数据时,它工作得非常好.
my controller bring data from spring app data but it does not get displayed in form. When I put constants in data it works perfectly fine.
这是我在 JS 控制器中的代码
here is my code in JS controller
sampleApp.controller('searchCourseController', ['$scope', '$http',
function($scope, $http, $routeParams, ngTableParams ) {
$scope.courses = {};
$scope.searchButton=function () {
var actionUrl = 'searchCourse';
var textToSearch = $("#txtTitle").val();
if (textToSearch.length == 0) {
alert("Please provide search criteria. Blank search is not allowed");
/* $("#loader-overlay").fadeOut();
$("#bg-loader").fadeOut(); */
return;
}
$http.get(actionUrl+"?title="+escape(textToSearch))
.success(
function(data, status, headers, config) {
$scope.courses = data;
console.log($scope.courses);
})
.error(
function(data, status, headers, config) {
});
};
$scope.editCourseButton=function () {
alert ("edit");
};
}]);
我用来显示数据的html如下
and my html that i am ussing to display data is following
<table class="table">
<thead>
<tr>
<th>Course Name</th>
<th>Status</th>
<th class="hidden-xs">Publishing status</th>
<th class="hidden-xs">Group Name</th>
<th class="hidden-xs">Rating</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="course in $scope.courses">
<td>{{course.name}}</td>
<td>{{course.courseStatus}}</td>
<td>{{course.coursePublishStatus}}</td>
<td>{{course.courseGroupName}}</td>
<td>{{course.courseRating}}</td>
</tr>
</tbody>
</table>
具有固定数据的相同代码显示在数据表中而没有问题,这可能是什么问题.
What could be the problem as the same code with fixed data gets displayed in data table without an issue.
谢谢,
推荐答案
你不能在视图中指定 $scope,因为它没有定义:
You can't specify $scope in the view, since it's not defined:
<tr ng-repeat="course in $scope.courses">
成为
<tr ng-repeat="course in courses">
这篇关于AngularJS ng-repeat 不显示表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文