Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the data using $http.get

In my app Im trying to fetch the json array from the DB using the $http.get, on execution Im not able see the fetched data on my view. But in my browser console Im able to see the response showing number of json array data:array[5]on expanding each array able to see the entered values in the array. So how can I display the data fetched in my view page.

 var brandList=[];
var successCallBack=function(response){
  $log.info(response);
  brandList=response;
};
 var errorCallBack=function(response)
 {
   $log.info(response);
 };
$http({
  method:'get',
  url:'http://local-serve:8081/route/listMake'})
  .then(successCallBack,errorCallBack);  
      return brandList;
}]); 
like image 592
Rudhra Avatar asked Jul 10 '26 17:07

Rudhra


1 Answers

The response in the entire response object. you need to extract value from it. Try running this URL in the browser. Now using the same URL, here's an example:

In JS,

$http.get('https://jsonplaceholder.typicode.com/photos/1')
   .then(function(response){
     $scope.title = response.data.title;
   })

And in HTML,

<p>
 The title is <i>{{title}}</i>
</p>
like image 103
sisyphus Avatar answered Jul 13 '26 07:07

sisyphus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!