1

I have a problem when i want to show some records from my databse in html page : i have an empty array in html page. I have a restful service that shows my json data : http://localhost:8080/produits

[{"id":1,"designation":"HP CDG","prix":123.0,"quantite":456},{"id":2,"designation":"Samsung galaxy","prix":905.0,"quantite":7}]

I am using spring boot application

the javascript file : 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);

})

});

my index.html page :

    <!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>
7
  • I think that your problem come for the initialization of the products before the call to $http. Can you remove it and try again. Commented Mar 5, 2017 at 12:40
  • I did but the same problem.. Commented Mar 5, 2017 at 12:42
  • Calling localhost:8080/produits in web browser, do you have a result? Commented Mar 5, 2017 at 12:43
  • I see that you hardcoded the URL to your REST service. Is your app running on another port ? Commented Mar 5, 2017 at 12:43
  • in your success callback log the data to the console and see what you're getting back. Commented Mar 5, 2017 at 13:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.