I'm beginner in angular. I'm using $http to get JSON data from the server by clicking on a button. my end goal is to fill all my HTML input forms with the server returning data automatically. I'm trying to do this with a forEach loop:
$http.post("check_ad", postData, config).then(function (response) {
angular.forEach(response.data.getValue, function(value, key) {
$scope.key = value;
});
});
My HTML is:
<input type="text" ng-model="test">
<input type="text" ng-model="test2">
The server returning data is:
{"getValue":{"test":"hello","test2":"world"}}
My problem is that "key" variable is not working for me. If I'm trying to go direct without the "key" it's working OK:
$http.post("check_ad", postData, config).then(function (response) {
angular.forEach(response.data.getValue, function(value, key) {
$scope.test = value;
$scope.test2 = value;
});
});
My question is how i'm using $scope with variable? And another question is if there is a better way to do that Instead using forEach?
Thanks you :)