Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS ng repeat未显示表格数据_Javascript_Angularjs_Ng Repeat_Ngtable - Fatal编程技术网

Javascript AngularJS ng repeat未显示表格数据

Javascript AngularJS ng repeat未显示表格数据,javascript,angularjs,ng-repeat,ngtable,Javascript,Angularjs,Ng Repeat,Ngtable,我的控制器从spring应用程序数据中获取数据,但它不会显示在表单中。当我在数据中放入常数时,它工作得非常好 这是我在JS控制器中的代码 sampleApp.controller('searchCourseController', ['$scope', '$http', function($scope, $http, $routeParams, ngTableParams ) { $scope.courses = {};

我的控制器从spring应用程序数据中获取数据,但它不会显示在表单中。当我在数据中放入常数时,它工作得非常好

这是我在JS控制器中的代码

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如下

<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>
<input class="form-control" type="text" placeholder="Title" id="txtTitle" ng-change="search()" ng-model="txtToSearch">

课程名称
地位
出版状况
组名
评级
{{course.name}
{{course.courseStatus}}
{{course.coursePublishStatus}
{{course.courseGroupName}
{{course.coursering}}
在数据表中显示具有固定数据的同一代码时,可能会出现什么问题


谢谢,

您不能在视图中指定$scope,因为它没有定义:

<tr ng-repeat="course in $scope.courses">

变成

<tr ng-repeat="course in courses">

除了在ng repeat中的$scope.courses中省略$scope之外,您可能还需要在$http.get success回调中使用$scope.$apply()来更新范围。这将在异步进程之后将视图更新为更新的$scope.courses绑定

例如:

$http.get(actionUrl+"?title="+escape(textToSearch))
 .success(function(data, status, headers, config) {
                $scope.courses = data;

                $scope.$apply(); // used $scope.$apply() to update the scope.
                console.log($scope.courses);
            })
        .error(
            function(data, status, headers, config) {
            });
  });

对ng更改调用搜索函数,如下所示

<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>
<input class="form-control" type="text" placeholder="Title" id="txtTitle" ng-change="search()" ng-model="txtToSearch">

如果我执行$scope.apply();JS在控制台错误中给了我以下错误:$摘要已经在进行中,我看到的示例似乎没有这种问题。$scope.$watch($$phase){$scope.$apply();}会有帮助。@AmmarAli在
console.log($scope.courses)
中显示了什么?