Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.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的html页面中显示rest服务中的json数据_Javascript_Angularjs_Json_Spring Boot_Spring Restcontroller - Fatal编程技术网

Javascript 无法在带有angularjs的html页面中显示rest服务中的json数据

Javascript 无法在带有angularjs的html页面中显示rest服务中的json数据,javascript,angularjs,json,spring-boot,spring-restcontroller,Javascript,Angularjs,Json,Spring Boot,Spring Restcontroller,当我想在html页面中显示数据库中的一些记录时,我遇到了一个问题:我在html页面中有一个空数组。 我有一个显示json数据的restful服务: [{“id”:1,“名称”:“HP CDG”,“prix”:123.0,“quantite”:456},{“id”:2,“名称”:“三星银河”,“prix”:905.0,“quantite”:7}] 我正在使用spring启动应用程序 javascript文件:app.js var app = angular.module("MyApp",[]) a

当我想在html页面中显示数据库中的一些记录时,我遇到了一个问题:我在html页面中有一个空数组。 我有一个显示json数据的restful服务:

[{“id”:1,“名称”:“HP CDG”,“prix”:123.0,“quantite”:456},{“id”:2,“名称”:“三星银河”,“prix”:905.0,“quantite”:7}]

我正在使用spring启动应用程序

javascript文件:app.js

var app = angular.module("MyApp",[])
app.controller("ProduitController",function($scope,$http){
$scope.produits=null;
$http.get("http://localhost:8080/produits")
.success(function(data){

    $scope.produits=data;
})
.error(function(err){
    console.log(err);

})

});
我的index.html页面:

    <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<title>catalogue</title>
<script type="text/javascript" src="angular/angular.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body ng-app="MyApp" ng-controller="ProduitController">
    <h3>Test</h3>
    <div class="Container">
        <table>
            <tr>
                <th>ID</th>
                <th>Designation</th>
                <th>Prix</th>
                <th>Quantite</th>
            </tr>
            <tr ng-repeat="p in produits">
                <td>{{p.id}}</td>
                <td>{{p.designation}}</td>
                <td>{{p.prix}}</td>
                <td>{{p.quantite}}</td>
            </tr>
        </table>
    </div>
</body>
</html>

目录
试验
身份证件
任命
大奖赛
定量
{{p.id}}
{{p.designation}}
{{p.prix}}
{p.quantite}}

我认为您的问题在于调用$http之前产品的初始化。你能删除它然后再试一次吗?我也这样做了,但问题是一样的..调用web浏览器,你有结果吗?我看到你硬编码了REST服务的URL。你的应用程序是否在另一个端口上运行?在你的成功回调日志中,将数据发送到控制台,并查看你得到了什么。我认为你的问题在于调用$http之前产品的初始化。你能删除它然后再试一次吗?我也这样做了,但问题是一样的..调用web浏览器,你有结果吗?我看到你硬编码了REST服务的URL。您的应用程序是否在另一个端口上运行?在成功回调中,将数据记录到控制台,然后查看您得到了什么。