0

Hello i want to display results from https://developer.edamam.com/edamam-docs-recipe-api this api or to put them into array

vm.search = function(){
  var req2 = {
      method: "GET",


    url:"https://api.edamam.com/search?q="+vm.searchText+"&app_id=myID&app_key=myKey"


  }
  $http(req2).then(
      function(resp){
        console.log(resp);
        vm.recepti = resp.data.Search;
        console.log(vm.recepti);


      }, function(resp){
          vm.message = 'error';
      });

};

i dont quite understand this particular api, or how do i display all recepies (names, images and other parameters that it has) from query result that users inputs in field with vm.searchText text box thanks for help in advance

vm.recepti is an emtpy array ,

enter image description here when i go to query link i get this now how do i access properties based on this?

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
StefanBRT
  • 43
  • 1
  • 6
  • That is where debugging help. Check what `resp` actually is. Does it have any `data` property? Is this `data` property also an object? Does it have any `Search` property? keep asking questions and keep on debugging and you will find something meaningful. – palaѕн Dec 28 '17 at 16:27

1 Answers1

0

Try to do something like this:

vm.recepti = resp.data.hits;

  • thanks but i want only this part : http://prntscr.com/hth7kk when i try resp.data.hits.recipe; it wont work for some reason – StefanBRT Dec 28 '17 at 18:46
  • That's why resp.data.hits is an array with N elements. So, if do you want only the first element, you can access it like : resp.data.hits[0].recipe. But if you want all the elements, you can use a for loop to loop over all the elements. Something just like this: resp.data.hits.forEach(function (item){ console.log(item.recipe); }); It will print all the recipes, from a array. – Matheus Castro Dec 29 '17 at 19:06