Bilel Troudi
Bilel Troudi

Reputation: 13

build a list from an http request

I have this code in my controller :

 @RequestMapping("/allU")
    public List<Utilisateur> AllU()
    {
        return UtilisateurRepo.findAll();

    }

in my code angularjs when I put :

$scope.list=$http.get("/allU");
alert($scope.list);

the result would object Object but not the json list. when I make the request ( / Allu ) directly in the browser I get the json list. I wanted to know how to retrieve this list from the http request

Upvotes: 0

Views: 25

Answers (1)

Tarun Dugar
Tarun Dugar

Reputation: 8971

You are not using a promise. Use a promise like this:

$http.get("/allU").then(function(data) {
    $scope.list = data; //data from api
}, function(error) {
    //handle in case api fails
});

We have to use a promise because the ajax calls are async in nature and we need a promise to handle the data returned when the request completes.

Upvotes: 2

Related Questions