I am trying to call angular/ajax get the value from API and want setup my result in expecting results format. I try with my code but its calling twice times i don't know where i am mistaking please suggest
$http.get('v1/res')
.success(function (data) {
$scope.results = [];
angular.forEach(data.data, function(value, key){
$scope.results.push({id: value.id});
$scope.results.push({text: value.name});
});
});
//Expecting result
$scope.results = [
{id: 1, text: 'A'},
{id: 2, text: 'B'},
{id: 3, text: 'C'},
{id: 4, text: 'D'},
{id: 5, text: 'E'},
{id: 6, text: 'F'},
{id: 7, text: 'G'},
{id: 8, text: 'H'},
];
$scope.results.push({'id': value.id, 'text': value.name});?