var app = angular.module("mymodule",[]);
app.controller("employeeController",function($scope,$http){
var url ="data/records.json";
$http.get(url).success(function(response){
$scope.employees =response;
});
});
Asked
Active
Viewed 116 times
2

Sajeetharan
- 216,225
- 63
- 350
- 396
-
1So what doesnt work? Are there errors in the console? – tymeJV Mar 27 '17 at 16:00
-
`.success` has been deprecated.. and do use `response.data` – Pankaj Parkar Mar 27 '17 at 16:01
-
What is the output of response? (i.e. `console.log(response);`) – Ben Mar 27 '17 at 16:01
-
Thanks. its working – Mar 27 '17 at 16:04
-
@KhairulIslamTonmoy you checked the answer? – Sajeetharan Mar 27 '17 at 16:33
4 Answers
3
You should access response.data
,also replace success with then,.success
has been deprecated.
$http.get(url).then(function(response){
$scope.employees =response.data;
});

Sajeetharan
- 216,225
- 63
- 350
- 396
1
.success
is deprecated since angular version 1.4 To catch the promise you can use then
.
Note that response of the then
return data inside the data property. so you need to access the data property of that response.
$http.get(url).then(function(response){
$scope.employees =response.data
});

Sachila Ranawaka
- 39,756
- 7
- 56
- 80
-
That is inaccurate. The `.success` method was deprecated in version 1.4, removable by configuration in version 1.5, and completely removed in version 1.6. – georgeawg Mar 27 '17 at 17:49
0
Try this way
app.controller("paymentRequestController", ["$scope", "$http", function ($scope, $http) {
$scope.payment_method_info = [];
$scope.rate = 0;
$scope.getPaymentInfo = function () {
$http({
method: "POST",
url: url,
}).success(function (response) {
if (response.length > 0) {
$scope.rate = response[0].rate;
$scope.payment_method_info = response;
} else {
$scope.rate = 0;
$scope.payment_method_info = [];
}
});
};
},
]);

Khairul Islam Tonmoy
- 177
- 3
- 8
-1
i don't have enought reputation. i want to add on @Jayanta reply this is another syntax:
.success(function (data, status, headers, config) {
deffered.resolve(data);
so when you try to add "data" to console.log(data) it will dislay the right data.

Hamdy
- 430
- 1
- 6
- 19
-
1i am sorry sir, i think you are using the angular version less then 1.6 and the code have some syntax error. the code is traditional way and the success and error method is not working in 1.6 version. – Jayanta Mar 27 '17 at 16:57