【问题标题】:Browser not shows any data or Error浏览器不显示任何数据或错误
【发布时间】:2017-10-26 20:04:29
【问题描述】:

我使用 node js 和 angular js 以及车把作为视图引擎。我正在尝试基本的应用程序/示例,但没有在浏览器端获取任何数据。浏览器上显示的数据是空白的。

我在浏览器上做了 console.log,我得到的数据是 [object] [object]。

Included angular:
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>

On handlebars page : [enter image description here][1]table:

<table ng-controller="myCtrl" border="1">
    <li ng-if="records.length === 0">( No items in this list yet! )</li>

    <tr ng-repeat="x in records">
      <td>{{x.Name}}</td>
      <td>{{x.Country}}</td>  
    </tr>
    </table>

<script>
var app = angular.module('tennisApp',[]);
app.controller('myCtrl', function($scope, $http) {
    $scope.data = [];
    var request = $http.get('http://localhost:3030/aitaAngular');    
    request.success(function(response) {            
        $scope.data = response;  
        console.log(response);
        console.log($scope.data);
    });
    request.error(function(response){
        console.log('Error: ' + response);
    });
});
</script>

【问题讨论】:

  • 您的控制器名称不同。使用相同的控制器名称。你的 ng-app 在哪里?
  • 您将数据设置为$scope.data,但在ng-repeat 中是records
  • @Dinesh 我在正文中定义了 ng-app
  • @Pengyy 哦,是的。让我们试试
  • 我在正文中添加了 ng-app。我忘了在这里添加它

标签: javascript angularjs json node.js handlebars.js


【解决方案1】:

那里的控制器名称错误。 您在视图中使用了 myCrtl,在 javascript 中使用了 userDetails 也没有 ng-app

            <!DOCTYPE html>
            <html>
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
            <body>
            <div ng-app="myApp"> 
            <table ng-controller="userDetails" border="1">
                <li ng-if="records.length === 0">( No items in this list yet! )</li>
                <tr ng-repeat="x in records">
                  <td>{{x.Name}}</td>
                  <td>{{x.Country}}</td>  
                </tr>
                </table>                    
            </div>
            <script>
            var app = angular.module('myApp', []);
            app.controller('userDetails', function($scope, $http) {
                $scope.data = [];
                var request = $http.get('http://localhost:3030/aitaAngular');    
                request.success(function(response) {            
                    $scope.data = response;  
                    console.log(response);
                    console.log($scope.data);
                });
                request.error(function(response){
                    console.log('Error: ' + response);
                });
            });
            </script>
            </body>
            </html>

【讨论】:

    猜你喜欢
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 2019-06-03
    • 2017-03-27
    • 1970-01-01
    • 2016-08-22
    相关资源
    最近更新 更多