How to catch the return of the post on my Scope Angularjs?

Asked

Viewed 70 times

-1

My variable scope.id_propertie returns Undefined. Some way to catch her off?

$http.post("consults/properties.php", {
  'action': 'list_properties'
}).then(function(response) {
  let data = response;
  for (let i = 0; i < data.length; i++) {
    $scope.id_propertie = data[i].id_propertie;
  }
});

console.log($scope.id_propertie);
  • The logic is the same: https://answall.com/a/413864/99718

  • I didn’t understand your answer could ne give an example with the top code?

1 answer

1

The angular returns the data in response.data and not in response.

Tip: debug the output of responseto see what is coming out, if it is a different object than expected, it is very common to notice the error by debugging or simply writing to console.log().

In this case you should adjust this line: data = response; for let data = response.data;, or better const data = response.data;.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.